2017-10-20 57 views
1

我有一个旧的应用卫生组织图像上载已经开始失败,代码中使用它下面:AWS Objective-C的图像上载

dispatch_semaphore_t SEMA = dispatch_semaphore_create(0);

NSError * __block anError = nil; 

AWSS3PutObjectRequest *por = [AWSS3PutObjectRequest new]; 
por.key = key; 
por.bucket = bucket; 
por.contentType = @"image/png"; 
por.contentLength = [NSNumber numberWithUnsignedLong:[UIImagePNGRepresentation(image) length]]; 
por.body = UIImagePNGRepresentation(image); 
por.ACL = AWSS3ObjectCannedACLPublicRead; 
[[AWSS3 defaultS3] putObject:por completionHandler:^(AWSS3PutObjectOutput * _Nullable response, NSError * _Nullable error) { 
    anError = error; 
    dispatch_semaphore_signal(sema); 
}]; 

dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); 

if (anError) { 
    NSException *exception = [NSException exceptionWithName:@"NoahPutObjectException" reason:[anError description] userInfo:nil]; 
    @throw exception; 
} 

我可以确认存储桶没有改变,并在正确的区域。我收到的错误是这样的:

Error Domain=com.amazonaws.AWSS3ErrorDomain Code=0 "(null)" UserIn 

fo={RequestId=F5B5BFDB18414371, 
    Bucket=BUCKETREDACTED, HostId=HOSTIDREDACTED, 
    Message=The bucket you are attempting to access must be addressed 
using the specified endpoint. Please send all future requests to this endpoint., Code=PermanentRedirect, 
    Endpoint=s3.amazonaws.com} 

我已更新为使用最新的吊舱,但仍然收到此错误。

回答

0

对我来说,就像您使用“s3.amazonaws.com”作为您的端点一样,您需要改为使用特定于区域的端点地址,如“s3-us-west-1.amazonaws.com”。按地区划分的正确的端点URL可以在这里找到:http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

+0

我到底该如何设置?这是一个旧的继承代码库,所以我有点迷路了。 – steventnorris

+0

呵呵,你已经对我有了一个感觉,能够真正阅读那个旧的代码库。我会先从:grep s3.amazonaws.com - 基本上你必须找到该URL是硬编码还是保存在配置中并更改它。 – CodeWriter23

+1

Gotcha。我看到了一些相关信息,但我认为它只适用于我读过的非美国桶。没有意识到它也适用于美国。 – steventnorris