objective c - How to upload a UIImage to S3 with AWS iOS SDK v2 -


the readme page in github (https://github.com/aws/aws-sdk-ios-v2) has example upload image, file path url:

awss3transfermanageruploadrequest *uploadrequest = [awss3transfermanageruploadrequest new]; uploadrequest.bucket = yourbucket; uploadrequest.key = yourkey; uploadrequest.body = yourdataurl; // <<<< nsurl uploadrequest.contentlength = [nsnumber numberwithunsignedlonglong:filesize]; 

but, if have uiimage in memory (without file path)? possible upload uiimage (or it's nsdata) s3 using sdk?

would easier manually use http api (using afnetworking)?

even though awsiossdkv2 doesn't support uploading images memory, can save file , upload it.

//image want upload uiimage* imagetoupload = [uiimage imagenamed:@"imagetoupload"];   //convert uiimage  nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *filepath = [[paths objectatindex:0] stringbyappendingpathcomponent:[nsstring stringwithformat:@"%@.png", datekey]]; [uiimagepngrepresentation(imagetoupload) writetofile:filepath atomically:yes];  nsurl* fileurl = [nsurl fileurlwithpath:filepath];  //upload image awss3transfermanageruploadrequest *uploadrequest = [awss3transfermanageruploadrequest new]; uploadrequest.body = fileurl; uploadrequest.bucket = aws_bucket_name; uploadrequest.key = @"yourkey"; uploadrequest.contenttype = @"image/png"; [[transfermanager upload:thumbnailuploadrequest] continuewithexecutor:[bfexecutor mainthreadexecutor] withblock:^id(bftask *task) {     if(task.error == nil) {         nslog(@"woot");     }     return nil; }]; 

Comments