I am trying to upload a image using AFHTTPSessionManager through REST API call.
following are my code
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager.requestSerializer setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
[manager POST:@"http://localhost:8888/uploadImage/100" parameters:nil constructingBodyWithBlock:^(id formData) {
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
} success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"success:%@", responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error:%@", error);
}];
Response is going to field block and getting following error
Error:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9cbc690 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set., NSUnderlyingError=0x9cbaf00 "Request failed: length required (411)"}
Any one have idea on this issue ?
Thanks