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

        

  • 相关阅读:
    HDU dp递推 母牛的故事 *
    自制权限框架(二)注解
    自制权限框架(二)注解
    自制权限框架(二)注解
    自制权限框架(二)注解
    iOS Sprite Kit教程之申请和下载证书
    iOS Sprite Kit教程之申请和下载证书
    iOS Sprite Kit教程之申请和下载证书
    白领创业做起了小龙虾的生意,如今公司日销售额达30万元
    她将小镇上的童装生意做到了线上,这位夫妻因此获得了大丰收
  • 原文地址:https://www.cnblogs.com/sandyzhang/p/9843367.html
Copyright © 2011-2022 走看看