简体   繁体   English

s3 iOS中的Bucket图像上传问题(Objective C)

[英]s3 Bucket Image upload issue in iOS (Objective C)

I am trying to upload images to s3 bucket from my Xcode Project for the very first time it works perfectly fine but after uploading one image it gives me error each time following is the error 我试图将图像从我的Xcode项目上传到s3存储桶,这是第一次它完全正常工作但是在上传一个图像之后它每次出错都会给我错误

AWSiOSSDK v2.4.12 [Error] AWSCredentialsProvider.m line:577 | AWSiOSSDK v2.4.12 [错误] AWSCredentialsProvider.m行:577 | __44-[AWSCognitoCredentialsProvider credentials]_block_invoke.353 | __44- [AWSCognitoCredentialsProvider凭证] _block_invoke.353 | Unable to refresh. 无法刷新。 Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=IdentityPool 'us-west-2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' not found.}] 错误是[错误域= com.amazonaws.AWSCognitoIdentityErrorDomain Code = 10“(null)”UserInfo = {__ type = ResourceNotFoundException,message = IdentityPool'us-west-2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'not found。}]

And code That i am using is this 我正在使用的代码就是这个

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

It looks like you're telling the credentials provider to look at us-east-1, but your identity pool is in us-west-2. 看起来你正在告诉凭证提供者查看us-east-1,但你的身份池在us-west-2中。 Since it doesn't exist in us-east-1, you get that resource not found error. 因为它在us-east-1中不存在,所以你得到的资源没有找到错误。

If you update the region AWSRegionUSEast1, you should be good to go. 如果您更新AWSRegionUSEast1区域,那么您应该很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM