• 基于AFNetworking的多张图片上传


      // 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:@"上传失败"];

        }];

  • 相关阅读:
    JDBC批量删除某一用户下的触发器
    DWZ框架修改默认主页(转)
    JSP页面中的js方法遍历后台传来的自定义对象的List
    JDBC获取表注释
    你的显示方式安全么?JSTL中c:out标签介绍
    tomcat启动报错
    PPP协议体系的实现
    Linux下的虚拟Bridge实现
    三皇五帝
    贴近原理层的科技发展
  • 原文地址:https://www.cnblogs.com/somebodywx/p/5724607.html
Copyright © 2020-2023  润新知