//上传图片
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSArray* imageS =@[@"图片1",@"图片2"];//图片数组
[managerPOST:urlparameters:parameterDicconstructingBodyWithBlock:^(id _NonnullformData) {
for(inti =0; i = imageS.count , i++)
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
formatter.dateFormat=@"yyyyMMddHHmmss";
NSString*str=[formatterstringFromDate:[NSDatedate]];
NSString*fileName=[NSStringstringWithFormat:@"%@.jpg",str];
UIImage*image =imageS[i];
NSData*imageData =UIImageJPEGRepresentation(image,0.5);
[formDataappendPartWithFileData:imageDataname:@"progressImgList"fileName:fileNamemimeType:@"image/png"];
}
}progress:^(NSProgress*_NonnulluploadProgress) {
//上传进度
}success:^(NSURLSessionDataTask*_Nonnulltask,id _NullableresponseObject) {
//成功
}failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
//失败
}];
}
//上传视频
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSArray* videoS =@[@"视频1",@"视频2"];//视频数组
[managerPOST:urlparameters:parameterDicconstructingBodyWithBlock:^(id _NonnullformData) {
for(inti =0; i = videoS.count , i++)
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
formatter.dateFormat=@"yyyyMMddHHmmss";
NSString*str=[formatter stringFromDate:[NSDate date]];
NSString*fileName=[NSString stringWithFormat:@"%@.mp4",str];
NSData*fileData = [NSData dataWithContentsOfFile:videoS[i]];
[formData appendPartWithFileData:fileData name:@"uploadFileList" fileName:fileName mimeType:@"application/octet-stream"];
}
}progress:^(NSProgress*_NonnulluploadProgress) {
//上传进度
}success:^(NSURLSessionDataTask*_Nonnulltask,id _NullableresponseObject) {
//成功
}failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
//失败
}];
}