// //http://test.yuliaokaihei.com/Api/Public/test /////////图片上传示例// UIImage * image = [UIImage imageNamed:@"room"];//// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];// //接收类型不一致请替换一致text/html或别的// manager.responseSerializer = [AFHTTPResponseSerializer serializer];// NSURLSessionDataTask * task = [manager POST:@"http://test.yuliaokaihei.com/Api/User/uploadFace" parameters:nil constructingBodyWithBlock:^(id_Nonnull formData) {
// NSData *imageData =UIImageJPEGRepresentation(image,1);
// NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
// formatter.dateFormat =@"yyyyMMddHHmmss";
// NSString *str = [formatter stringFromDate:[NSDate date]];
// NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
// //上传的参数(上传图片,以文件流的格式)
// [formData appendPartWithFileData:imageData
// name:@"file"
// fileName:fileName
// mimeType:@"image/jpeg"];
// } progress:^(NSProgress *_Nonnull uploadProgress) {
// //打印下上传进度
// } success:^(NSURLSessionDataTask *_Nonnull task,id _Nullable responseObject) {
// //上传成功
// NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil];
// NSLog(@"%@",dic[@"des"]);
// } failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {
// //上传失败
// NSLog(@"%@",error);
// }];
直接复制代码到需要盛传图片的地方就可以。