Assertion failure appending to multipart form
afnetworking, ios, objective-c
Solution
After looking into the `AFNetworking/AFHTTPClient.m` code, my guess is that your `imageData` is `nil`.
Problem
I'm migrating my app from ASIHTTPRequest to AFNetworking to talk to the backend API. Everything seems to work fine except by image uploading. I've used different examples over the internet, but running it on my app always causes a crash. ``` 2013-02-22 17:02:28.680 MyApp[1477:907] *** Assertion failure in -[AFStreamingMultipartFormData appendPartWithHeaders:body:], AFNetworking/AFHTTPClient.m:885 2013-02-22 17:02:28.687 MyApp[1477:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: body' ``` The problem seems to be here: ``` NSMutableURLRequest *request = [[MyServiceAPIClient sharedClient] multipartFormRequestWithMethod:@"POST" path:@"/api/method" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { [formData appendPartWithFileData:imageData name:@"face" fileName:@"face.jpg" mimeType:@"image/jpeg"]; }]; ``` `MyServiceAPIClient` is a singleton class with as given in the AFNetworking iOS example app. If I comment the `appendPartWithFileData` part everything runs fine, obviously it won't send my picture. If I replace the multipart form request with a ordinary post request, it works. The only problem is appending my `NSData` to the form. Any observations? Thanks.