iOS AFNetworking上传图片到服务器
2015-10-10 14:04
609 查看
字段 | 必填 | 类型 | 说明 |
userid | true | int | 用户id |
img | false | file | 上传头像(最大200KB)A |
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFHTTPRequestSerializer serializer]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; [manager POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { NSData *imageData = UIImagePNGRepresentation(image); [formData appendPartWithFileData:imageData name:@"img" fileName:@"23456789.jpg" mimeType:@"image/jpeg"]; <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);"><span style="white-space:pre"> </span>//@"img" <span style="line-height: normal; font-family: 'Heiti SC Light';">服务器上的</span>img <span style="line-height: normal; font-family: 'Heiti SC Light';">字段</span> <span style="line-height: normal; font-family: 'Heiti SC Light';">容易出错</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span>//@"23456789.jpg" <span style="line-height: normal; font-family: 'Heiti SC Light';">图片名</span> <span style="line-height: normal; font-family: 'Heiti SC Light';">随便填</span></p> //@"image/jpeg" 图片类型 } success:^(AFHTTPRequestOperation * _Nonnull operation, id responseObject) { HeadImage *headImage = [HeadImage objectWithJSONData:responseObject]; success(headImage); } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * error) { NSLog(@"%@",error); failure(error); }];
相关文章推荐
- iOS开发系列--通知与消息机制
- iOS抽奖转盘动画之CAAnimation动画
- [IOS]对项目重命名
- 【IOS 开发学习总结-OC-39】★★ios开发之 MVC 模式
- iOS 被键盘遮挡时,带有textfield的tableview自动上移
- Customizing Navigation Bar and Status Bar in iOS 7
- ios随机数,and()、random()、arc4random()
- IOS 腾讯微博开放平台 SDK 初体验
- 【iOS】文件上传小记
- IOS 推送
- IOS控件 动画操作 与 CALayer 简单操作
- IOS 系统文字转英文字母
- IOS delegate注册推送
- IOS横屏事件
- IOS汉字排序
- iOS开展-clang: error: unknown argument: '-websockets'解决方案
- iOS流量监控
- ios子控件超过了父控件的frame范围,超过的部分不显示
- iOS开发中@property的属性weak nonatomic strong readonly等介绍
- ios开发中WebView,去除(自定义)JS中Alert显示的网址