Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Upload from in-memory UIImage #42

Closed
marioizquierdo opened this issue Aug 16, 2014 · 7 comments
Closed

S3 Upload from in-memory UIImage #42

marioizquierdo opened this issue Aug 16, 2014 · 7 comments
Labels
duplicate This issue or pull request already exists question General question

Comments

@marioizquierdo
Copy link

I have a UIImage that doesn't have a NSUrl path. How could I upload that image to S3 with the SDK?

AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = yourBucket;
uploadRequest.key = yourKey;
uploadRequest.body = yourDataURL; // <<< I ONLY HAVE A UIIMAGE, NOT A URL
uploadRequest.contentLength = [NSNumber numberWithUnsignedLongLong:fileSize];
@yosuke-matsuda
Copy link
Contributor

You can save the image to a file (e.g. in the temporary directory), then pass the file path as an NSURL. You can read this thread for more details.

@marioizquierdo
Copy link
Author

Well in my case, I don't want to put the image in the file because it is supposed to be unaccessible by the user (the file that we store in the filesystem is encrypted, the UIImage is decrypted in memory).

Also our files are not too big, so we don't need to worry about long uploads.

I found someone else writing about how to upload NSData in this StackOverflow question, but I am still trying to make it work... let's see where I end up today.

@marioizquierdo
Copy link
Author

I though I could make it work like this:

AWSS3PutObjectRequest *req = [AWSS3PutObjectRequest new];
req.bucket = bucket;
req.key = imgName;
req.contentType = @"image/png";
req.body = imgData;
req.contentLength = [NSNumber numberWithInteger:[imgData length]];

AWSS3 *transferManager = [[AWSS3 alloc] initWithConfiguration:gAWSServiceConfiguration];
[[transferManager putObject:req] continueWithBlock:^id(BFTask *task) {
    if(task.error) {
        NSLog(@"ERROR: %@", task.error);
    } else {
        NSLog(@"SUCCESS: %@", task.result);
    }
    return nil;
}];

But this code doesn't work. For some reason, it is logging the following error:

AWSiOSSDKv2 [Error] AWSURLResponseSerialization.m line:148 | +[AWSXMLResponseSerializer serializerWithResource:actionName:] | can not find PutObject.json file in the project
AWSiOSSDKv2 [Error] AWSURLRequestSerialization.m line:104 | +[AWSXMLRequestSerializer serializerWithResource:actionName:] | can not find PutObject.json file in the project
AWSiOSSDKv2 [Verbose] AWSURLRequestSerialization.m line:152 | -[AWSXMLRequestSerializer serializeRequest:headers:parameters:] | Request body: []
ERROR Domain=com.amazonaws.AWSXMLBuilderErrorDomain Code=901 "JSON definition File is empty or can not be found" UserInfo=0x1d19eff0 {NSLocalizedDescription=JSON definition File is empty or can not be found}

Then, knowing that uploading images from memory is not supported on SDKv2 I tried to install SDKv1, but I might give up and have to start thinking on uploading the images to my backend first and then upload from there :(

@yosuke-matsuda
Copy link
Contributor

Have you read and followed README.md and Set Up the SDK for iOS? It sounds like you are missing the service definition JSON files.

@marioizquierdo
Copy link
Author

Yes I did. I guess there is something wrong about this step:

Drag and drop the following JSON files, located in the service-definitions directory, into your project.

I did put those files on some folder inside my project. How can I know if they are placed in the right place? Maybe "drag and drop" is not enough

@temitope
Copy link

temitope commented Sep 9, 2014

@marioizquierdo you may need to explicitly add them via Xcode's "Add Files to (Project Name" so they are included when built. Im going to try now

@vvit
Copy link

vvit commented Dec 11, 2014

@marioizquierdo AWSS3 *transferManager should be retained, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question General question
Projects
None yet
Development

No branches or pull requests

4 participants