2016-12-29 128 views
1

我想從我的Xcode項目將圖像上傳到S3桶的第一次它運行完美,但它給上傳一個圖片後,我的每一次錯誤以下是錯誤S3存儲圖片上傳問題

AWSiOSSDK v2.4.12 [錯誤] AWSCredentialsProvider.m線:577 | __44- [AWSCognitoCredentialsProvider憑證] _block_invoke.353 |無法刷新。誤差[誤差域= com.amazonaws.AWSCognitoIdentityErrorDomain代碼= 10 「(空)」 的UserInfo = {__類型= ResourceNotFoundException,消息= IdentityPool'US-西2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx找不到。}]

和代碼,我使用本

- (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; 
    }]; 
} 

回答

0

它看起來像你告訴憑據提供看着我們,東-1,但你的身份游泳池在美國西部-2。由於它不存在於us-east-1中,因此您找不到該資源錯誤。

如果您更新區域AWSRegionUSEast1,您應該很好。