本文介绍了AFNetworking 2.0 API用于多部分表格上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用于上传多部分表单的AFNetworking 2.0方法是什么,即使用 AFHTTPSessionManager
或 AFHTTPRequestOperationManager
What is the AFNetworking 2.0 method for uploading a multipart form i.e. With AFHTTPSessionManager
or AFHTTPRequestOperationManager
以下是一些AFNetworking< 2.0代码:
Here is an example of some AFNetworking < 2.0 code:
[[ASAPIClient sharedClient] enqueueHTTPRequestOperation:[[ASAPIClient sharedClient] HTTPRequestOperationWithRequest:[[ASAPIClient sharedClient] multipartFormRequestWithMethod:@"POST" path:@"/some/url" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
if(_selectedPhoto.image)
{
NSData *imageData = UIImageJPEGRepresentation([_selectedPhoto image], 0.5);
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}
}] success:^(AFHTTPRequestOperation *operation, id responseObject) {
if([[responseObject objectForKey:@"result"]isKindOfClass:[NSDictionary class]] )
{
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}]];
推荐答案
ASAPIManager
是 AFHTTPRequestOperationManager
[[ASAPIManager sharedManager] POST:@"/some/url" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
if(_profileImageView.image){
[formData appendPartWithFileData:UIImageJPEGRepresentation(_profileImageView.image, 0.5) name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
这篇关于AFNetworking 2.0 API用于多部分表格上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!