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. Redisson-Parent 2.5.0 和 3.0.0 发布

    Redisson-Parent 2.5.0 和 3.0.0 发布了,Redisson 是基于 Redis 服务之上构建的分布式.可伸缩的 Java 数据结构,高级的 Redis 客户端. Rediss ...

  2. javascript的异步编程方法

    一,callback 回调函数 即函数f1和函数f2的关系是f1(f2()); f2作为f1()的回调函数,在f1执行过程中就开始执行f2,先执行线程的主要逻辑,将比较耗时的任务放在后面执行. 回调函 ...

  3. 解决Only a type can be imported. com.mysql.jdbc.Connection resolves to a package的报错问题

    写jsp加载数据驱动以后老是提示Only a type can be imported. com.mysql.jdbc.Connection resolves to a package的错误,然而改成 ...

  4. node.js学习笔记【1】

    http://howtonode.org/how-to-install-nodejs http://www.mcclean-cooper.com/valentino/cygwin_install/

  5. Qt线程(2) QThread中使用WorkObject

    一般继承QThread的WorkThread都会在重载的run()中创建临时的WorkObject,这样能确定这个WorkObject在该thread中使用 那如果这个WorkObject是个Sing ...

  6. 极简版 react+webpack 脚手架

    目录结构 asset/ css/ img/ src/ entry.js ------------------------ 入口文件 .babelrc index.html package.json w ...

  7. 原生javascript里jsonp的实现原理

    ajax不能跨域,jsonp可以跨域 跨域的核心思想:      调用(拿到的接口),定义(jsonp核心处理器)分别是不同的script标签里面进行跨script取数据(只有get方式进行取数据 ) ...

  8. Android Studio 总结

    1:添加插件 File->Setting->plugins->Browse repoistories

  9. linux之各个文件夹作用

    /bin 二进制可执行命令  /dev 设备特殊文件  /etc 系统管理和配置文件  /etc/rc.d 启动的配置文件和脚本  /home 用户主目录的基点,比如用户user的主目录就是/home ...

  10. c++ 语言细节

    #include <iostream>using namespace std;int main(){     cout << "\nHello World!\n&qu ...