- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. [self request];
} - (void)saveImage
{
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[imageData writeToFile:[self GetTempPath] atomically:YES];
} -(NSString *)GetTempPath{
NSString *tempPath =[NSString stringWithFormat:@"%@/upload.jpg",NSTemporaryDirectory()];
return tempPath;
} - (void)request
{
NSDictionary *postDic = [[NSDictionary alloc]init];
[postDic setValue:@"test" forKey:@"userId"];
[postDic setValue:[self GetTempPath] forKey:@"file"]; [self uploadImage:postDic];
} - (void)uploadImage:(NSDictionary *)dic
{
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:postUrl]]; // 通常数据是以’application/x-www-form-urlencoded’格式发送的,如果上传了二进制数据或者文件,那么格式将自动变为‘multipart/form-data’注意要和服务器统一。
[request addRequestHeader:@"Content-Type" value:@"multipart/form-data"];
//超时时间
request.timeOutSeconds = ; //定义异步方法
[request setDelegate:self];
[request setRequestMethod:@"POST"];
[request setDidFailSelector:@selector(commonRequestDidFailed:)];
[request setDidFinishSelector:@selector(commonRequestDidSuccess:)]; //post的数据
id key, value;
for (int i = ; i < [dic allKeys].count; i++)
{ key = [keys objectAtIndex: i];
value = [params objectForKey: key];
NSLog (@"Key: %@ for value: %@", key, value); if ([key isEqualToString:@"file"]) {
[request setFile:value forKey:key];
[request setShouldStreamPostDataFromDisk:YES];
}
else
{
[request setPostValue:value forKey:key];
} } [request startSynchronous];
}

最新文章

  1. 【原创】SQL审核系统
  2. 比较核心的技术了 虚拟ip的一种实现方式(手工添加和C#添加)
  3. [Hibernate] - Annotations
  4. python(二)拾遗
  5. 【学习笔记】【C语言】数据
  6. MIT 2012分布式课程基础源码解析-线程池实现
  7. [置顶] 【Git入门之十一】标签管理
  8. C#线程池ThreadPool的理解
  9. 使用Z3破解简单的XOR加密
  10. 蛋疼的_after_insert
  11. [Codeforces702F]T-Shirts——非旋转treap+贪心
  12. 【XSY3154】入门多项式 高斯消元
  13. 《剑指offer》 二维数组中的查找
  14. gitlab--ci文件
  15. AIX中vi编辑器使用
  16. openresty 一些可选的模板引擎
  17. 调用azkaban接口,upload 本地zip文件
  18. Strategic Game HDU - 1054(最小顶点覆盖)
  19. Cognos11中通过URL传参访问动态Report
  20. Idea的注入和自动编译配置

热门文章

  1. jps命令使用
  2. 利用Excel批量高速发送电子邮件
  3. QiniuUpload- 一个方便用七牛做图床然后插入markdown的小工具
  4. js_day8
  5. .Net的PDF转图片
  6. asp.net实现将网页存为mht格式文件,类似于网页另存为mht功能
  7. C#读取XML配置文件
  8. 利用MiddleGen-hibernate-r5生成hbm文件及POJO文件
  9. Light oj 1030 二分查找
  10. Cocos2d-x 3.0 场景切换