图片一定要先压缩,转成data,不然就会报错
AFHTTPSessionManager*manager = [AFHTTPSessionManagermanager];
manager.responseSerializer.acceptableContentTypes= [NSSetsetWithObjects:@"application/json",
@"text/html",
@"image/jpeg",
@"image/png",
@"application/octet-stream",
@"text/json",
@"image/jpg",
@"text/plain",
nil];
[managerPOST:[NSStringstringWithFormat:@"%@%@",POSTURL,WXHOMESENDDYNAMIC]parameters:dictconstructingBodyWithBlock:^(id_NonnullformData) {
// 上传多张图片
for(NSIntegeri =0; i
{
//取出单张图片二进制数据
NSData*imageData =UIImageJPEGRepresentation(self.imageArr[i],0.8);
NSLog(@"%@",imageData);
// 上传的参数名,在服务器端保存文件的文件夹名
NSString* Name = [NSStringstringWithFormat:@"file"];
// 上传filename
NSString* fileName = [NSStringstringWithFormat:@"%@.jpg", Name];
[formDataappendPartWithFileData:imageDataname:NamefileName:fileNamemimeType:@"image/jpeg"];
}
}progress:^(NSProgress*_NonnulluploadProgress) {
NSLog(@"%@",uploadProgress);
}success:^(NSURLSessionDataTask*_Nonnulltask,id_NullableresponseObject) {
if([responseObject[@"code"]integerValue]==10000) {
[selfshowText:@"上传成功"];
[self.navigationControllerpopViewControllerAnimated:YES];
}else{
[selfshowText:[NSStringstringWithFormat:@"%@",responseObject[@"message"]]];
NSLog(@"%@",responseObject);
}
}failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
[selfshowError:error];
}];