[英]s3 Bucket Image upload issue in iOS (Objective C)
我試圖將圖像從我的Xcode項目上傳到s3存儲桶,這是第一次它完全正常工作但是在上傳一個圖像之后它每次出錯都會給我錯誤
AWSiOSSDK v2.4.12 [錯誤] AWSCredentialsProvider.m行:577 | __44- [AWSCognitoCredentialsProvider憑證] _block_invoke.353 | 無法刷新。 錯誤是[錯誤域= com.amazonaws.AWSCognitoIdentityErrorDomain Code = 10“(null)”UserInfo = {__ type = ResourceNotFoundException,message = IdentityPool'us-west-2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'not found。}]
我正在使用的代碼就是這個
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
initWithRegionType:AWSRegionUSEast1
identityPoolId:@"us-west-2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
return YES;}
-(void)uplaodImageToS3 :(NSString *)userId
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"user_%@.png", userId]];
NSData *imageData = UIImagePNGRepresentation(uploadedImage);
[imageData writeToFile:path atomically:YES];
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
_uploadRequest = [AWSS3TransferManagerUploadRequest new];
_uploadRequest.bucket = @"dellonybucket";
_uploadRequest.ACL = AWSS3ObjectCannedACLPublicRead;
_uploadRequest.key = [NSString stringWithFormat:@"images/user_%@.png", userId];
_uploadRequest.contentType = @"image/png";
_uploadRequest.body = url;
__weak RegistrationViewController *weakSelf = self;
_uploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend){
dispatch_sync(dispatch_get_main_queue(), ^{
weakSelf.sizeUplaoded = totalBytesSent;
weakSelf.filesize = totalBytesExpectedToSend;
[weakSelf update];
});
};
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
[[transferManager upload:_uploadRequest]continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id _Nullable(AWSTask * _Nonnull task) {
if (task.error) {
//NSLog(@"%@",task.error);
[self hideHud];
[self alertView:@"Image uplaoding failed please try again." title:@"Unsuccessfull"];
}
if (task.result) {
//AWSS3TransferManagerUploadOutput *uploadOutput = task.result;
[self hideHud];
[self alertView:@"User registerd successfully." title:@"Successfull"];
}
return nil;
}];
}
看起來你正在告訴憑證提供者查看us-east-1,但你的身份池在us-west-2中。 因為它在us-east-1中不存在,所以你得到的資源沒有找到錯誤。
如果您更新AWSRegionUSEast1區域,那么您應該很高興。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.