Sending more than one image with AFNetworking

China☆狼群 提交于 2019-12-04 05:54:55

Use a multipartFormRequest for that use below method:

- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
                                               path:(NSString *)path
                                         parameters:(NSDictionary *)parameters
                          constructingBodyWithBlock:(void (^)(id <AFMultipartFormDataProxy>formData))block;

For example like this:

 NSURLRequest* request = [[YourHTTPClient sharedHTTPClient] multipartFormRequestWithMethod:@"POST"
                     path:path
                     parameters:dict
                     constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                          [formData appendPartWithFileData:data1
                                                      name:@"image1"
                                                      fileName:@"image1.jpg"
                                                      mimeType:@"image/jpeg"];
                          [formData appendPartWithFileData:data2
                                                      name:@"image2"
                                                      fileName:@"image2.jpg"
                                                      mimeType:@"image/jpeg"];
                     }
                 }];

How are you creating the UIImage objects that get passed into your sendImageMsgWithPath: method? Are you creating them using imageWithData: (or similar)? If so, I have seen problems like this when trying to reuse an NSMutableData. It seems that even after you create the UIImage, the subsystem still needs to read that data at a later time. And if you have since reused that NSMutableData, the image will be corrupted.

If this is the case, I recommend that you use a new NSMutableData to create each UIImage.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!