zoukankan      html  css  js  c++  java
  • 'Invalid parameter not satisfying: body'

    afnetwork图片上传的时候出错,出现错误

    2015-11-09 15:47:59.086 videoPro[3207:132795] *** Assertion failure in -[AFStreamingMultipartFormData appendPartWithHeaders:body:], /Users/zhanglingxiang/Documents/videoPro/AFNetworking/AFURLRequestSerialization.m:793

    2015-11-09 15:48:01.655 videoPro[3207:132795] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: body'

     

    代码:

     NSData *imageData = UIImageJPEGRepresentation(image,0.1f);
        
        //转码成UTF-8  否则可能会出现错误
        NSString *URLTmp = [NSString stringWithFormat:@"%@/photoUpload",SERVER];
        
        NSString *URLTmps = [URLTmp stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
        URLTmp = URLTmps;
        
        NSDictionary* dic = [NSDictionary dictionaryWithObject:self.userName forKey:@"user"];
        
        NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:URLTmp parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            
            [formData appendPartWithFileData:imageData name:@"headerImg" fileName:@"123.png" mimeType:@"image/png"];
            
            
        } error:nil];
        
        AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
        
        NSProgress *progress = nil;
    
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
            
            if (error) {
                
                NSLog(@"Error: %@", error);
                
            } else {
                NSLog(@"%@",responseObject);
                NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
                NSString* strHead = [NSString stringWithFormat:@"%@/%@",IMGSERVER,dic[@"url"]];
    //            [[NSUserDefaults standardUserDefaults] setObject: forKey:@"userHead"];
                [imageView sd_setImageWithURL:[NSURL URLWithString:strHead]];
                
                //头像上传成功
                MBProgressHUD* hud = [[MBProgressHUD alloc] initWithView:self.view];
                [self.view addSubview:hud];
                hud.mode = MBProgressHUDModeCustomView;
                hud.labelText = @"头像上传成功";
                [hud showAnimated:YES whileExecutingBlock:^{
                    sleep(2);
                } completionBlock:^{
                    [hud removeFromSuperview];
                    return;
                }];
    
                
            }
        }];
        [uploadTask resume];
    

      

     

    改了几种方法,都不行,最后发现是image没有值,也是醉了。。

     

     

  • 相关阅读:
    js定时跳转
    MySQL跨表更新字段 工作记录
    windows下安装phpcms html/ 文件夹不可写的一种错误以及解决方法
    linux清理僵尸进程
    JQuery实现隔行变色和突出显示当前行 效果
    windows下配置lamp环境(4)---安装MySQL数据库5.6
    windows下配置lamp环境(5)---配置MySQL5.6
    windows下配置lamp环境(3)---配置PHP5.4
    windows下配置lamp环境(0)---软件获取
    windows下配置lamp环境(2)---配置Apache服务器2.2.25
  • 原文地址:https://www.cnblogs.com/symen/p/4950112.html
Copyright © 2011-2022 走看看