How to upload an Android file to S3 bucket with public permission

此生再无相见时 提交于 2019-12-13 05:38:01

问题


I keep trying to upload a file to an s3 bucket. But the file is never public for viewing. I have to manually make the files/folder in the bucket public (for every upload) for it to be view able.

Is there a way to upload an Android file (bitmap) with the default permission to be public for viewing during. I would prefer to do this programmatically, if possible. I've checked the s3 docs, couldn't find anything helpful.


回答1:


To make all objects in your bucket public by default, view the answers to this question or this question.

To specify public access for each file when you are uploading them via Android, set the ACL on the PutObjectRequest like this:

PutObjectRequest putObjectRequest = new PutObjectRequest()
    .withCannedAcl(CannedAccessControlList.PublicRead)

It doesn't look like you can set the ACL in one step with TransferUtility at this time: https://github.com/aws/aws-sdk-android/issues/63

So after uploading the file via TransferUtility you would need to do the following:

s3client.setObjectAcl(bucketName, keyName, CannedAccessControlList.PublicRead);



回答2:


Yes, it is very easy for those guys, who is using TransferUtility, use below method for uploading any file for public readable form using TransferUtility in android,

transferUtility.upload(String bucketName,String key,File file,CannedAccessControlList cannedAcl)

Example:

transferUtility.upload("MY_BUCKET_NAME","FileName",your_file,CannedAccessControlList.PublicRead);


来源:https://stackoverflow.com/questions/36191788/how-to-upload-an-android-file-to-s3-bucket-with-public-permission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!