• 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); }];

        

  • 相关阅读:
    ORACLE中seq$表更新频繁的分析
    VmWare平台Windows Server 2012 无响应宕机
    SQL Challenge ——快速找到1-100之间缺失的数
    ORACLE推导参数Derived Parameter介绍
    SQL SERVER 数据库各版本功能对比
    Jsp中格式化时间戳的常用标签
    SQL Server 2014 Database Mail重复发送邮件特殊案例
    采用HTML5之“data
    多线程之策略模式
    docker attach卡住,和exec的选择
  • 原文地址:https://www.cnblogs.com/sandyzhang/p/9843367.html
Copyright © 2020-2023  润新知