【问题标题】:s3 Bucket Image upload issue in iOS (Objective C)iOS 中的 s3 Bucket Image 上传问题(目标 C)
【发布时间】:2017-05-13 09:52:41
【问题描述】:

我第一次尝试将图像从我的 Xcode 项目上传到 s3 存储桶,它工作得非常好,但是在上传一张图像后,每次都会出现错误,以下是错误

AWSiOSSDK v2.4.12 [错误] AWSCredentialsProvider.m 行:577 | __44-[AWSCognitoCredentialsProvider 凭证]_block_invoke.353 |无法刷新。错误是 [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=IdentityPool 'us-west-2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 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;
    }];
} 

【问题讨论】:

    标签: objective-c image-uploading amazon-cognito s3-bucket


    【解决方案1】:

    您似乎在告诉凭据提供程序查看 us-east-1,但您的身份池位于 us-west-2。由于它在 us-east-1 中不存在,因此您会收到该资源未找到错误。

    如果您更新区域 AWSRegionUSEast1,您应该可以继续使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      相关资源
      最近更新 更多