您的位置:首页 > 移动开发 > IOS开发

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



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: