码迷,mamicode.com
首页 > Web开发 > 详细

基于AFNetworking的多张图片上传

时间:2016-08-01 10:37:05      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

  // 1.创建请求管理对象

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    //2.发送请求

    NSMutableDictionary * paramters = [NSMutableDictionary dictionary];

    paramters[@"uid"] = [self getUserID];

    PKLog(@"paramters==%@",paramters);

    // 转换成NSData保存

  NSArray *imageArr = [NSArray arrayWithObjects:self.bindingBtn.imageView.image,   self.positiveBtn.imageView.image,self.BackBtn.imageView.image,nil];

  NSString *urlStr = [NSString stringWithFormat:@"%@%@",PKServerIP,@"/api/v1/validate/getimg"];

[manager POST:urlStr parameters:paramters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {

        

        PKLog(@"self.imageArray=%@",imageArr);

        for (int i=0; i<imageArr.count; i++) {

            UIImage * image =imageArr[i];

            NSData *data = UIImageJPEGRepresentation(image, 1.0);

            NSString *name =[NSString stringWithFormat:@"image%d.png",i];

            NSString *formKey =[NSString stringWithFormat:@"image%d",i];

            NSString *type = @"image/png";

            [formData appendPartWithFileData:data name:formKey fileName:name mimeType:type];

        }

        PKLog(@"formData=%@",formData);

 

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {

       PKLog(@"responseObject = %@",responseObject);

        [self HUDShowText:@"上传成功,我们将尽快为您审核" completBlock:^{

            //返回

            [self.navigationController popViewControllerAnimated:YES];

        }];        

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        PKLog(@"error=%@",error);

        [self HUDShowText:@"上传失败"];

    }];

基于AFNetworking的多张图片上传

标签:

原文地址:http://www.cnblogs.com/somebodywx/p/5724607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!