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没有值,也是醉了。。

'Invalid parameter not satisfying: body'的更多相关文章

  1. IOS 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString'

    转载自:http://i.cnblogs.com/EditPosts.aspx?postid=4012011 今天想写一个请求的天气,好的,废话不多说,先贴代码: 使用AFNetWorking 发送g ...

  2. iOS 9 地图定位崩溃 n: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'

    报错详情: *** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/ ...

  3. iOS文件上传文件URL错误Invalid parameter not satisfying: fileURL'

    一:iOS文件上传提示URL错误 Invalid parameter not satisfying: fileURL' 二:解决方法: NSString *imagePath = [[NSBundle ...

  4. 安装yii2时出错 Invalid Parameter – yii\base\InvalidParamException

    最近composer安装yii2的时候页面报了这个错,应该是bower的前端资源位置改变的缘故! Invalid Parameter – yii\base\InvalidParamException ...

  5. Oracle 记录插入时“Invalid parameter binding ”错误

    出现这种错误的原因可能有一下几种: 由于OracleParameter[] parameters:中parameters的个数和对应的插入SQL语句中的冒号个数不等: 参数个数和冒号个数相等,但是如下 ...

  6. 关于ImageMagick出现无效参数(invalid parameter)的解决方法

    Windows 命令行 运行"convert logo.jpg  f:\parseWord\tmp\logo.png" 时显示 “无效参数(Invalid Parameter)” ...

  7. java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang.String 转载

    java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang. ...

  8. Failed to set MokListRT: Invalid Parameter Something as gone seriously wrong: import_mok_state() failed: Invalid Parameter

    今天yum update升级centos7,重启后发现开不了机,报错如下: Failed to set MokListRT: Invalid ParameterSomething as gone se ...

  9. 源码剖析Yii错误 Invalid parameter number: no parameters were bound

    ActiveRecord使用的一个陷阱导致 Invalid parameter number: no parameters were bound 请看下面的例子 $criteria = new CDb ...

随机推荐

  1. 《TCP/IP详解卷1:协议》第2章 链路层-读书笔记

    章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...

  2. Oracle数据库高效sql语句的整理

    业务需求说明:由于之前公司后台APP端有一个document表,该表中包含了所有的信息,新的需求就是通过该表创建出一个新的用户表(usertable)和一个档案表(document,该表只保留原doc ...

  3. Ubuntu16.04 操作

    1. 无法获得锁 /var/lib/dpkg/lock - open (11: 资源临时不可用) sudo rm /var/cache/apt/archives/locksudo rm /var/li ...

  4. CSS中相对定位与绝对定位

    看了几个讲解定位的博客,觉得还不错,分享之: 博客一:http://blog.sina.com.cn/s/blog_4bcf4a5e010008o0.html 文章中,主要需要参考的有两点: 1,相对 ...

  5. (spring-第18回【AOP基础篇】) 创建切面

    一.   在创建增强一节中,增强被织入到目标类的所有方法中,假设我们希望有选择地织入到目标类某些特定的方法中,就需要使用切点进行目标连接点的定位. 二.   spring通过org.springfra ...

  6. HttpClient(4.3.3)实例讲解

    HttpClient的作用强大,真的是十分强大. 本实例是基于v4.3.3写的,,作用是模拟登陆后进行上下班打卡,,,使用htmlparser进行解析返回的html文件 关于HttpClient的一些 ...

  7. Android Priority Job Queue (Job Manager):多重不同Job并发执行并在前台获得返回结果(四)

     Android Priority Job Queue (Job Manager):多重不同Job并发执行并在前台获得返回结果(四) 在Android Priority Job Queue (Jo ...

  8. ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java

    Given two integers representing the numerator and denominator of a fraction, return the fraction in ...

  9. Toolkit.getImage获取图片

    public class Img { private static final Toolkit tk = Toolkit.getDefaultToolkit(); public static fina ...

  10. Spring加载resource时classpath*:与classpath:的区别

    http://blog.csdn.net/kkdelta/article/details/5507799   classpath: 第一个匹配的 classpath*:多个组件中的可匹配的