zoukankan      html  css  js  c++  java
  • AFN上传多张图片

    AFN上传多张图片代码:

    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    
        sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
    
        //        self.responseSerializer = [AFHTTPResponseSerializer serializer];
    
        AFJSONResponseSerializer *response = [AFJSONResponseSerializer serializer];
    
        response.removesKeysWithNullValues = YES;
    
        sessionManager.responseSerializer = response;
    
        sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"text/javascript",@"text/json",@"text/plain",nil];
    
    
        NSDictionary *params = @{@"english_name":self.englishTextField.text,
    
                                  @"age":self.ageString,
    
                                  @"sex":self.sexString};
    
     
    
        [sessionManager POST:[NSString stringWithFormat:@"%@/api/v1/personInfo/collect_info",BaseURL] parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
    
    //        [formData appendPartWithFileURL:[NSURL fileURLWithPath:self->fullPath] name:@"imageFile" fileName:@"currentImage.png" mimeType:@"image/png" error:nil];
    
            // 上传文件
    
            NSUInteger i = 0 ;
    
            for (UIImage * image in self.imgArr) {
    
                //image的分类方法
    
                UIImage *  resizedImage =  image;
    
                NSData * imgData = UIImageJPEGRepresentation(resizedImage, .5);
    
                //拼接data
           //name是服务器设置的接收图片文件的名字
           //fileName:自己起的区别于其他图片的名字
           //image/jpeg是服务器接收图片的格式
    [formData appendPartWithFileData:imgData name:[NSString stringWithFormat:@"image"] fileName:@"image.png" mimeType:@"image/jpeg"]; i++; } } progress:^(NSProgress * _Nonnull uploadProgress) { // @property int64_t totalUnitCount; 需要下载文件的总大小 // @property int64_t completedUnitCount; 当前已经下载的大小 //打印下上传进度 NSLog(@"上传进度 %lf",1.0 *uploadProgress.completedUnitCount / uploadProgress.totalUnitCount); } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"请求成功:%@",responseObject); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { //请求失败 [GKMessageTool showError:@"请求失败"]; NSLog(@"请求失败:%@",error); }];

        

  • 相关阅读:
    工作需求----表单多选框checkbox交互
    工作需求——JQ小效果分享下
    JQ返回顶部代码分享~~~~
    css 分享之background-attachment 属性
    CSS3学习之分享下transition属性
    css 伪元素分享!!!
    phpcm v9 任意调用分页/phpcm v9首页调用分页不起作用或者乱码
    facebook分享不能显示图片链接问题
    Fatal error: Uncaught SoapFault exception:解决办法
    VUE项目 启动提示 npn ERRT nissing script: dev解决办法
  • 原文地址:https://www.cnblogs.com/sandyzhang/p/9843367.html
Copyright © 2011-2022 走看看