IOS上传图片的方法
来源:互联网 发布:华为云服务器绑定域名 编辑:程序博客网 时间:2024/05/16 01:13
-(void)loadImage:(NSString*)aurl{ NSData *imageData; NSMutableData *postBody; NSString *stringBoundary, *contentType; NSURL *url = [NSURL URLWithString:aurl]; //将字符串转换为NSURL格式 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"1.jpg"]; imageData = [[NSData alloc] initWithContentsOfFile:path]; ASIFormDataRequest *aRequest = [[ASIFormDataRequest alloc] initWithURL:url]; stringBoundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"]; contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", stringBoundary]; [aRequest addRequestHeader:@"Content-Type" value:contentType]; postBody = [[NSMutableData alloc] init]; [postBody appendData:[[NSString stringWithFormat:@"\r\n\r\n--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"title\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"lighttable"] dataUsingEncoding:NSUTF8StringEncoding]]; // So Light Table show up as source in Twitter post NSString *imageFileName = [NSString stringWithFormat:@"photo.jpeg"]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upload\"; filename=\"%@\"\r\n",imageFileName] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:imageData]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"password\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"lighttablexxxxxxxx"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [aRequest setDelegate:self]; [aRequest appendPostData:postBody]; [aRequest setRequestMethod:@"POST"]; [aRequest startAsynchronous]; [postBody release]; [aRequest release];}
0 0
- IOS上传图片的方法
- IOS上传图片的方法
- IOS上传图片的方法
- iOS上传图片的方法
- iOS开发上传图片的方法
- IOS上传图片方法类
- IOS上传图片方法类
- IOS上传图片方法类
- IOS上传图片方法类
- iOS 上传图片方法总结
- iOS 上传图片方法总结
- iOS图片上传-AFNetWorking的图片上传
- 图片上传的方法!
- 上传图片的方法
- 上传图片的方法
- iOS - 调用相机相册的方法 + 上传图片
- ios 表单上传图片和参数的2种方法
- IOS图片上传的代码
- Android学习之路--Activity篇(生命周期)
- IOS上传照片(自己的代码整理了一下)
- 再见,2014
- 关于xcode 6.0+上 iOS8.0+ 模拟器不弹出虚拟键盘和没有中文输入法的解决方案
- 浅谈高内聚、低耦合
- IOS上传图片的方法
- 【记录】Coolpy开机自启之Ubuntu
- 获取app应用的公钥
- 火狐浏览器下载乱码问题
- 指定maven的目录路径
- JavaScript核心指南(JavaScript. The Core.)
- Android Studio安装说明(2014.12)
- 一种侧滑菜单,值得学习
- 编程设计模式-代理模式