AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/html",@"application/json",nil];
[manager POST:urlString parameters:_tempMutableDic constructingBodyWithBlock:^(id_Nonnull formData) {
if(weakself.isVideo ==YES)
{
NSData *yaSuoData = UIImageJPEGRepresentation(_Img,0.5);
[formData appendPartWithFileData:yaSuoData name:@"imgfile"fileName:@"tian.jpg"mimeType:@"multipart/form-data"];
[formData appendPartWithFileData:weakself.videodata name:@"videofile"fileName:@"tianvideo1.mov"mimeType:@"video/quicktime"];
}else
{
for(UIImage *upImginweakself.photosArray)
{
NSData *yaSuoData = UIImageJPEGRepresentation(upImg,1.0);
[formData appendPartWithFileData:yaSuoData name:@"imgfile"fileName:@"tian.jpg"mimeType:@"multipart/form-data"];
}
}
} progress:^(NSProgress *_NonnulluploadProgress) {
floattheProgress = uploadProgress.completedUnitCount*1.0/uploadProgress.totalUnitCount;
NSLog(@"%f",theProgress);
hud.progress = theProgress;
// hud.labelText = [NSString stringWithFormat:@"上传中:%@ %",(unsigned long)beforeCount,(unsigned long)(_pictureArr.count-1)];
} success:^(NSURLSessionDataTask *_Nonnulltask,id _NullableresponseObject) {
hud.hidden =YES;
NSLog(@"%@",responseObject);
if([responseObject[@"result_code"] integerValue] ==100)
{
[weakself showTiShiMessage:@"上传成功"];
[weakself.navigationController popViewControllerAnimated:YES];
}else
{
[weakself showTiShiMessage:responseObject[@"result_msg"]];
}
} failure:^(NSURLSessionDataTask *_Nullabletask, NSError *_Nonnullerror) {
NSLog(@"%@",error.description);
hud.hidden =YES;
[weakself showTiShiMessage:@"上传失败"];
}];
本文标题:使用AF上传图片视频的使用
本文链接:https://www.haomeiwen.com/subject/mpkjfqtx.html
网友评论