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

        

  • 相关阅读:
    169. Majority Element
    283. Move Zeroes
    1331. Rank Transform of an Array
    566. Reshape the Matrix
    985. Sum of Even Numbers After Queries
    1185. Day of the Week
    867. Transpose Matrix
    1217. Play with Chips
    766. Toeplitz Matrix
    1413. Minimum Value to Get Positive Step by Step Sum
  • 原文地址:https://www.cnblogs.com/sandyzhang/p/9843367.html
Copyright © 2011-2022 走看看