ios - Issue while uploading Image -


step 1: here creating request

nsmutableurlrequest *request1 = [[afhttprequestserializer serializer] multipartformrequestwithmethod:@"post"                                                                                            urlstring:[nsstring stringwithformat:@"%@%@", api_main_url, image_upload]                                                                                           parameters:param constructingbodywithblock:^(id formdata) {             [formdata appendpartwithfileurl:[nsurl fileurlwithpath:strimagepath]                                        name:@"sendimage"                                    filename:[strimagepath lastpathcomponent]                                    mimetype:@"image/png"                                      error:nil];                                        } error:nil]; [request1 setvalue:authtoken forhttpheaderfield:@"authorization"]; 

step 2: here creating stream @ given location

[[afhttprequestserializer serializer] requestwithmultipartformrequest:request1                                            writingstreamcontentstofile:[nsurl fileurlwithpath:[strimagepath stringbydeletingpathextension]]                                                      completionhandler:^(nserror *error){ 

step 3: here creating uploading task.

        ///here file         nsprogress *progress = nil;         nsurlsessionuploadtask *uploadtask = [self.manager uploadtaskwithrequest:request1                                                                         fromfile:[nsurl fileurlwithpath:strimagepath]                                                                         progress:&progress                                                                completionhandler:^(nsurlresponse *response, id responseobject, nserror *error) {                                                                        nslog(@"response : %@\n\n responseobject : %@\n\n error : %@", response, responseobject, error);                                                                 }];         [uploadtask resume];     }                                                     }]; } 

my problem before application going background mode want write request httpbody(httpstream) @ given location using step:1 , step:2 , save request nsarray after writing httpstream in file(in application foreground) mean while i'll show image prepare upload.

then i'll start creating background task of step3: passing request request have stored nsarray. approach not able upload images.

but if call steps 1 one upload image on server, approach application should in foreground create request because need write httpbody @ give location.

please me come out problem stuck on last 2 week. application needed more 500 images uploading on server.

try this

 nsmutableurlrequest *request = [[afhttprequestserializer serializer] multipartformrequestwithmethod:@"post" urlstring:@"http://example.com/upload" parameters:nil constructingbodywithblock:^(id<afmultipartformdata> formdata) {                 [formdata appendpartwithfileurl:[nsurl fileurlwithpath:@"file://path/to/image.jpg"] name:@"file" filename:@"filename.jpg" mimetype:@"image/jpeg" error:nil];             } error:nil];  afurlsessionmanager *manager = [[afurlsessionmanager alloc] initwithsessionconfiguration:[nsurlsessionconfiguration defaultsessionconfiguration]];         nsprogress *progress = nil;          nsurlsessionuploadtask *uploadtask = [manager uploadtaskwithstreamedrequest:request progress:&progress completionhandler:^(nsurlresponse *response, id responseobject, nserror *error) {             if (error) {                 nslog(@"error: %@", error);             } else {                 nslog(@"%@ %@", response, responseobject);             }         }];          [uploadtask resume]; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -