如何在具有公共权限的情况下将Android文件上传到S3存储桶 [英] How to upload an Android file to S3 bucket with public permission

查看:131
本文介绍了如何在具有公共权限的情况下将Android文件上传到S3存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图将文件上传到s3存储桶.但是该文件永远不会公开供查看.我必须手动将存储桶中的文件/文件夹设为公开(对于每次上传),以便能够查看.

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.

有没有一种方法可以上传具有默认权限的Android文件(位图),以便在查看期间公开显示.如果可能的话,我希望以编程方式进行此操作.我检查了s3文档,找不到任何有用的信息.

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.

推荐答案

要默认使存储桶中的所有对象公开,请查看这个问题.

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

要在通过Android上传文件时为每个文件指定公共访问权限,请在PutObjectRequest上设置ACL,如下所示:

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)


目前看来您不能使用TransferUtility一步设置ACL: https://github.com/aws/aws-sdk-android/issues/63


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

因此,通过TransferUtility上传文件后,您需要执行以下操作:

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

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

这篇关于如何在具有公共权限的情况下将Android文件上传到S3存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆