尝试将数据从Android客户端上传到AWS时,我遇到了一个有趣的例外:
com.amazonaws.services.s3.model.AmazonS3Exception: x-amz-website-redirect-location header is not supported for this operation. (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: E3900749ACF1D979), S3 Extended Request ID: kFjMM7JVFSOxvaKlHgM0bVM5zKZAR/0K8qeMyt44vjvtMFcGk8CxY9gDBDs0sqWmr8r2jcCyENo=
位于中国地区的用户及数据已上传至under VPN
(香港)至西部地区http://currentidmedia.s3-ap-southeast-1.amazonaws.com
有关以下请求的更多详细信息:
PUT http://currentidmedia.s3-ap-southeast-1.amazonaws.com / Headers: (Expect: 100-continue, Content-Type: application/octet-stream, Date: Fri, 05 Jun 2015 10:13:01 GMT+00:00, Content-Length: 0, User-Agent: aws-sdk-android/2.2.1 Linux/3.4.0-g8a80a0e Dalvik/2.1.0/0 en_US com.amazonaws.mobileconnectors.s3.transfermanager.TransferManager/2.2.1, x-amz-website-redirect-location: /storage/emulated/0/DCIM/Camera/IMG_20150601_153423.jpg, Accept-Encoding: identity, Authorization: AWS AKIAIYL3TJHYVMB4SFRQ:dAkmOJxaIe5viO5kNjz74I/UKSc=, )
SDK中是否有错误,或者我没有以正确的方式使用它?
更新:
// set up credentials
AWSCredentials awsCredentials = new BasicAWSCredentials(
awsMetadata.getAccountId(),
awsMetadata.getSecretKey()
);
// set up request
PutObjectRequest request = new PutObjectRequest(
awsMetadata.getBucketName(),
FileUtil.extractNameFromPath(mediaItem.getContentUri()),
mediaItem.getContentUri()
);
// perform request
TransferManager transferManager = new TransferManager(awsCredentials);
transferManager.getAmazonS3Client().setRegion(getRegionForMedia(awsMetadata));
transferManager.upload(request, listener);
答案是我以不正确的方式使用了PutObjectRequest。它包含几个构造函数,如果您将String传递给内容而不是File,则需要设置重定向URL而不是数据路径。
然而,在修复之后,非中国存储桶出现了同样的SSLException
错误。我在VPN
下使用它而没有它。有关请求的更多详细信息,请参阅下文。
PUT https://currentidmedia.s3-ap-southeast-1.amazonaws.com / Headers: (Content-MD5: GI1M/hfrwwQHvHMBlmh/lA==, Expect: 100-continue, Content-Type: image/jpeg, Date: Sat, 06 Jun 2015 08:56:31 GMT+00:00, Content-Length: 2140572, User-Agent: aws-sdk-android/2.2.1 Linux/3.4.0-g8a80a0e Dalvik/2.1.0/0 en_US com.amazonaws.mobileconnectors.s3.transfermanager.TransferManager/2.2.1, Accept-Encoding: identity, Authorization: AWS AKIAIYL3TJHYVMB4SFRQ:fqWbHO6lBPsbI6lkcaHKhms8Hkw=, )
答案 0 :(得分:0)
x-amz-website-redirect-location
元数据仅适用于静态网站。静态网站具有不同的端点<bucket-name>.s3-website-<AWS-region>.amazonaws.com
。有关详细信息,请参阅http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html。你介意解释它的目的吗?我会看看是否有替代方案。