美文网首页
ios 上传file类型图片

ios 上传file类型图片

作者: 橘子味草莓 | 来源:发表于2017-12-08 15:57 被阅读16次

图片一定要先压缩,转成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];

}];

相关文章

网友评论

      本文标题:ios 上传file类型图片

      本文链接:https://www.haomeiwen.com/subject/uwweixtx.html