关闭

AFNetworking 一次上传多个文件的方法

34人阅读 评论(0) 收藏 举报

转自:http://www.devdiv.com/afnetworking_-blog-21666-51451.html

热度 1已有 4693 次阅读 2013-6-30 01:51|系统分类:iOS

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"];
                         }
                     }];

参见:
http://stackoverflow.com/questions/9559075/how-do-you-upload-multiple-files-with-afnetworking

另外参见官方wiki:
https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ

How do I upload a file?

Uploading a file is really just constructing an HTTP multi-part form body for a URL request.AFHTTPClient provides several helper functions that make this easy.

To create the request object, you would do something like:

NSData *imageData = UIImagePNGRepresentation(image);
NSURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
  [formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.png" mimeType:@"image/png"];
}];

You could then pass request into any request operation, likeAFJSONRequestOperation -JSONRequestOperationWithRequest:success:failure:.

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:17751次
    • 积分:498
    • 等级:
    • 排名:千里之外
    • 原创:20篇
    • 转载:91篇
    • 译文:0篇
    • 评论:0条