Note that there are some explanatory texts on larger screens.

plurals
  1. POSending more than one image with AFNetworking
    primarykey
    data
    text
    <p>I'm developing a messaging app, and users can also send pictures to one another.<br> When a user sends more than one picture I send them in parallel (I don't wait for the first one to finish upload before I send the second one) </p> <p>Before moving to <code>AFNetworking</code> I succeeded in doing this with <code>ASIFormDataRequest</code>, and indeed if I sent 2 images, both of them were transmitted in parallel and successfully delivered to the other user. </p> <p>When I try doing this with AFNetworking, I get some strange behavior.<br> I'll try to describe the case were user1 send two images too user2: </p> <ol> <li>User1 send image1 -> everything looks ok, I can see the upload progress. </li> <li>User1 then send image2 -> still looks ok, I can see the upload progress of both images </li> <li>image1 upload is finished -> user2 gets a corrupted image that looks like a combination of image1 and image2 together! </li> <li>image2 upload is finished -> user2 gets image2 successfully </li> </ol> <p>This is how I send an image </p> <pre><code>- (void)sendImageMsgWithPath:(NSString *)path image:(UIImage *)image success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure progress:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress { NSData *imageData = UIImageJPEGRepresentation(image, 0.5); // create the request NSURLRequest *request = [[AppClient sharedClient] multipartFormRequestWithMethod:@"POST" path:path parameters:nil constructingBodyWithBlock:^(id&lt;AFMultipartFormData&gt; formData) { [formData appendPartWithFileData:imageData name:@"image_name" fileName:@"image_name.jpg" mimeType:@"image/jpeg"]; }]; // create the operation AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease]; // set progress block [operation setUploadProgressBlock:progress]; //set completion blocks [operation setCompletionBlockWithSuccess:success failure:failure]; // set it to work in background [operation setShouldExecuteAsBackgroundTaskWithExpirationHandler:nil]; // add it to the operations queue [[AppClient sharedClient] enqueueHTTPRequestOperation:operation]; } </code></pre> <p>*** the path for both image uploads is the same: </p> <blockquote> <p>path = @"FrontEnd?cmd=sendimage&amp;fromuserid=3&amp;touserid=1&amp;" </p> </blockquote> <p>it will be added to the baseURL to create the coplete URL: </p> <blockquote> <p>@"<a href="http://somename.myftp.org:8080/web_proj/FrontEnd?cmd=sendimage&amp;fromuserid=3&amp;touserid=1" rel="nofollow noreferrer">http://somename.myftp.org:8080/web_proj/FrontEnd?cmd=sendimage&amp;fromuserid=3&amp;touserid=1</a>"</p> </blockquote> <p>This are the images I sent:<br> image1<br> <img src="https://i.stack.imgur.com/C56S5.png" alt="enter image description here"> </p> <p>image2<br> <img src="https://i.stack.imgur.com/Nzd8H.png" alt="enter image description here"> </p> <p>corrupted image<br> <img src="https://i.stack.imgur.com/FvSnw.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload