2017-10-20 78 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