Silverstar
Silverstar

Reputation: 463

AFNetworking won't allow large file upload

With AFNetworking I'm trying to upload an image (1280x990) with size: 33695. The code below works perfectly with smaller images (ie:390x390) but the larger image throws an error:

[client POST:@"/upload_image" parameters:nil constructingBodyWithBlock:^(id <AFMultipartFormData>formData) {

    [formData appendPartWithFileData:imageData name:@"image" fileName:@"image.jpg" mimeType:@"image/jpeg"];

} success:^(NSURLSessionDataTask * task, id responderData) {

} failure:^(NSURLSessionDataTask * task, NSError * error) {

}];

ERROR thrown:

NSDebugDescription = "JSON text did not start with array or object and option to allow fragments not set.";

I've searched many other posts and there doesn't seem to be anything referring to issues with a larger image size. Any suggestions?

Upvotes: 6

Views: 423

Answers (2)

heading_to_tahiti
heading_to_tahiti

Reputation: 795

I was having similar issues when I tried using AFNetworking. I have since switched to using RestKit and SDWebImage to handle the asynchronous loading and caching of images... and it works like a charm. You may want to take a look at this recent Quora post to better compare the differences between them.... Mainly the one con to Restkit was async and caching, but with little effort SDWebImage takes care of that with one line of code.

http://www.quora.com/iOS-Development/RestKit-vs-AFNetworking-What-are-the-pros-and-cons

Upvotes: 0

Trong Dinh
Trong Dinh

Reputation: 363

Based on the author of AFNetworking, plz use appendPartWithFileURL instead. Because the data will be stream from disk.

Upvotes: 1

Related Questions