Amazon S3 AWS将图像上传到文件夹

时间:2014-08-31 01:38:42

标签: java android amazon-web-services amazon-s3 image-uploading

在这里快速帮助,我希望将我的图像上传到我的亚马逊S3存储桶,我可以通过以下代码实现这一目标。

    s3Client = new AmazonS3Client( new BasicAWSCredentials( getString(R.string.s3_access_key), getString(R.string.s3_secret)));
//params contains file path
                        //PutObjectRequest por = new PutObjectRequest( getString(R.string.s3_bucket), params[0].getName(), params[0]);  
                        PutObjectRequest por = new PutObjectRequest( getString(R.string.s3_bucket), params[0].getName(), params[0]);
                        s3Client.putObject(por);

                        ResponseHeaderOverrides override = new ResponseHeaderOverrides();
                        override.setContentType( "image/jpeg" );
                        urlRequest = new GeneratePresignedUrlRequest( getString(R.string.s3_bucket), params[0].getName() );
                        urlRequest.setExpiration( new Date( System.currentTimeMillis() + 3600000 ) );  // Added an hour's worth of milliseconds to the current time.
                        urlRequest.setResponseHeaders( override );

我的相册中有一个文件夹,我无法将图像上传到该文件夹​​。

我尝试将图片上传到folder的内容是

PutObjectRequest por = new PutObjectRequest( getString(R.string.s3_bucket), params[0].getName(), params[0]).withKey("testmorya/");
                    s3Client.putObject(por);

BUCKET NAME:morya FOLDER NAME:testmorya

帮助表示赞赏

1 个答案:

答案 0 :(得分:8)

关键是如何构建密钥。要将“filea”放入“folderb”,只需将对象的键命名为“folderb / filea”。