简体   繁体   中英

AWS S3 SDKv2 and image upload ios on turk

I uploaded image to AWS S3 with with code :

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:pathComp];
    [UIImageJPEGRepresentation(myImage,0.9) writeToFile:filePath atomically:NO];
    filePath = [NSString stringWithFormat:@"file:///private%@", filePath];
    NSURL* fileUrl = [NSURL URLWithString:filePath];
    AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
    uploadRequest.key = key;
    uploadRequest.body = fileUrl;
    uploadRequest.contentType = @"image/jpeg";

It's uploaded normally, but in mechanical turk i can't open preview

This page contains the following errors:

error on line 1 at column 1: Document is empty
error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error. 

When creating a file URL using NSURL , you should use + fileURLWithPath: . You should change this line

NSURL* fileUrl = [NSURL URLWithString:filePath];

to

NSURL* fileUrl = [NSURL fileURLWithPath:filePath];

You should double check if the file was successfully uploaded using the AWS Management Console .

Also, by default, all Amazon S3 resources - buckets, objects, and related subresources - are private: only the resource owner, an AWS account that created it, can access the resource. You can modify ACL to change the permission.

Finded solution for AWS SDK v2 by PaulTaykalo

https://github.com/aws/aws-sdk-ios/issues/10

Link for fixed method http://pastie.org/9340740

Also added this code to swizzled method

[headers setValue:contentType forKey:@"Content-Type"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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