天天看点

aws s3 android sdk,如何通过aws SDK Android公开S3对象?(How do you make an S3 object public via the aws SDK An...

如何通过aws SDK Android公开S3对象?(How do you make an S3 object public via the aws SDK Android?)

我需要将我的上传内容公之于众。 我能够将图像上传到s3存储桶中。 但我无法通过编程方式公开我使用AWS SDK 2.1.10以下是我将图像上传到s3存储桶的代码

mUpload = getTransferManager().upload( AmazonConstants.BUCKET_NAME.toLowerCase(Locale.US), locationPath + super.getFileName() , mFile);

mUpload.waitForCompletion();

请帮帮我。 谢谢。

I need to make my upload as public. I was able to upload a image into s3 bucket. But i was unable to make that public by programmatically I am using AWS SDK 2.1.10 Below is my code for uploading image into s3 bucket

mUpload = getTransferManager().upload( AmazonConstants.BUCKET_NAME.toLowerCase(Locale.US), locationPath + super.getFileName() , mFile);

mUpload.waitForCompletion();

Please help me. Thank you.

原文:https://stackoverflow.com/questions/29641386

更新时间:2020-02-28 10:35

最满意答案

您需要在upload()使用PutObjectRequest 。

getTransferManager().upload(

new PutObjectRequest(String bucketName, String key, File file)

.withCannedAcl(CannedAccessControlList.PublicRead)

);

You need to use PutObjectRequest in upload().

getTransferManager().upload(

new PutObjectRequest(String bucketName, String key, File file)

.withCannedAcl(CannedAccessControlList.PublicRead)

);

2015-04-15

相关问答

要在没有Internet网关的情况下访问VPC中的S3,您需要使用S3端点 To access S3 within a VPC without an internet gateway you need to use a S3 Endpoint

在一个亚马逊aws论坛找到答案。 return s3Client.putObject(

new PutObjectRequest(bucketName, objectKey, inputStream, metadata)

.withCannedAcl(CannedAccessControlList.PublicRead));

答案是 .withCannedAcl(CannedAccessControlList.PublicRead) Found the answer in an

...

如果你更喜欢控制台的实现,那么你需要模拟它。 这意味着您的SDK客户端需要时创建中间“文件夹”。 您可以通过创建零大小的对象来实现这一点,其中的关键字以正斜杠结尾(如果这是您的'文件夹'分隔符)。 AWS控制台以这种方式运行,允许您创建'文件夹',因为许多AWS控制台用户比使用对象(和键)更适合使用文件夹和文件的概念。 然而,在我看来,很少需要这样做。 你的SDK客户端应该被实现来处理这些'文件夹'的存在与否。 更多信息在这里 。 If you prefer the console impleme

...

结果输出中n与n / 2的问题可能由实现中的错误所解释。 is.read()在循环中被调用两次,并且它的任何返回值都不是写入输出流,而只是第一个存储在val reads 。 实现应该改变成类似于: val byteStringBuilder = ByteString.newBuilder

val output = byteStringBuilder.asOutputStream

try {

var reads: Int = is.read() // note "var" instead of

...

AWS API端点可用作HTTP和HTTPS。 AWS SDK全部通过HTTPS连接。 因此,流量被加密。 The AWS API Endpoints are available as both HTTP and HTTPS. The AWS SDKs all connect via HTTPS. Thus, the traffic is encrypted.

我会回答我猜,因为没有人 - 这个应该有用 // create a new s3 object

var s3 = new AWS.S3();

var BUCKET_NAME = 'your-bucket-name';

var OLD_KEY = '/original-file.js';

var NEW_KEY = '/new-file.js';

// Copy the object to a new location

s3.copyObject({

Bucket: BUCKET_NAME,

...

当你调用PutObject时,你提供了bucket和对象的key。 您可以简单地组合这些来创建对象的URL,例如: http://s3.amazonaws.com/bucket/key (用于路径样式的URL)或 http://bucket.s3.amazonaws.com/key (适用于虚拟主机风格的网址) 因此,例如,如果您的存储桶是pablo并且对象关键字是dogs / toto.png ,请使用: http://s3.amazonaws.com/pablo/dogs/toto.png (

...

您需要在upload()使用PutObjectRequest 。 getTransferManager().upload(

new PutObjectRequest(String bucketName, String key, File file)

.withCannedAcl(CannedAccessControlList.PublicRead)

);

You need to use PutObjectRequest in upload(). getTransferManage

...

您没有将AWSServiceConfiguration传递给AWSS3TransferManager ,这导致了问题。 您需要更改以下行: var myTransferManager:AWSS3TransferManager = AWSS3TransferManager()

喜欢的东西 var myTransferManager:AWSS3TransferManager = AWSS3TransferManager.defaultS3TransferManager()

此外,您需要提前将默认服

...

如果您使用的是版本> = 2.6.0, dependencies {

compile ('com.amazonaws:aws-android-sdk-auth-core:[email protected]') { transitive = true; }

compile 'com.amazonaws:aws-android-sdk-core:2.6.+'

compile 'com.amazonaws:aws-android-sdk-s3:2.6.0'

}

1)创建IdentityMana

...