七牛云储存理解
来源:互联网 发布:o2o网络便利店系统 编辑:程序博客网 时间:2024/06/01 08:09
1.获取用户编辑之后的图片
if (editedImage) { photoPath = [CacheUtil cachePhoto:editedImage]; [self uploadPhoto]; }
2.通过缓存工具取出路径
2.1获取缓存文件的路径
`+ (NSString *)fileDirectory{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *documentDirectory = [paths objectAtIndex:0]; NSString * path = [NSString stringWithFormat:@"/%@",@"photoCache"]; NSString * fileDirectory = [documentDirectory stringByAppendingPathComponent:path]; NSFileManager * fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:fileDirectory]) { [fileManager createDirectoryAtPath:fileDirectory withIntermediateDirectories:YES attributes:nil error:nil]; } return fileDirectory;}`
2.2
新建一个图片的路径,将图片压缩0.5 之后存进一个nsdata 里面。
将这个data写道指定路径的位置,返回这个路径。
+ (NSString *)cachePhoto:(UIImage *)photo{ NSString * photoPath = [[self fileDirectory ] stringByAppendingPathComponent:[photo imageDataMd5]]; //具体这段代码的意义需要再考证 NSData * data = UIImageJPEGRepresentation(photo, 0.5); [data writeToFile:photoPath atomically:YES]; data = nil; return photoPath;}
3.上传这个路径下的文件
3.1 首先从服务端获取token凭证
- (void)uploadFilePath:(NSString *)filePath formatType:(NSString *)formatType sender:(CompletionHandler)handler{ requestHander = handler; [self requestToken]; m_filePath = filePath; m_formatType = formatType;}
3.2
请求token之后执行上传
- (void)requestToken{ [AFHttpTool getTokenSuccess:^(AFHTTPRequestOperation *operation, id response) { token = response[@"token"]; [self uploadFile]; //上传 } failure:^(id err) { AFHTTPRequestOperation * op = err; NSDictionary * response = [op.responseString jsonValue]; if (response[@"error"][@"message"]) { [[[UIAlertView alloc] initWithTitle:nil message:response[@"error"][@"message"] delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil, nil] show]; } }];}
3.3 上传图片到七牛
- (void)uploadFile{ QNUploadManager *upManager = [[QNUploadManager alloc] init]; NSData* data = [NSData dataWithContentsOfFile:m_filePath]; NSArray * tempQinniuStr = [m_filePath componentsSeparatedByString:@"/"]; //将上传过来的路径名分割成数组 //取出最后一个元素作为上传时候的key(相当于在七牛里面的唯一ID); NSString * qiniuFilePath2 = [NSString stringWithFormat:@"%@",[tempQinniuStr lastObject]]; [upManager putData:data key:qiniuFilePath2 token:token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) { NSLog(@"%@", info); NSLog(@"%@", key); qiniuFilePath = [NSString stringWithFormat:@"%@%@",kQiNiuDomain,key]; requestHander(YES, qiniuFilePath); //上传成功block返回七牛里面的路径 } option:nil];}
0 0
- 七牛云储存理解
- 浮点数储存理解误区
- 对Android内部储存的理解
- ThinkPHP之七牛云储存
- [深入理解计算机系统]数据储存-大小端法与补码
- 集成七牛云储存-上传图片Demo
- 七牛云储存实现iOS企业版分发
- 内部储存,外部储存。
- 处理器读并解释储存在存储器中的指令 读深入理解计算机系统
- 数据结构入门之树的储存结构中求树最大高度函数的理解与感想
- 七牛云储存视频播放器的选择方案
- 文件储存
- 储存过程
- sharePreferences 储存
- 储存数据
- 文件储存
- 数据储存
- 数据储存
- 面试-阿里
- UDP编程
- 20160329 HDU1023 Train Problem II(卡塔兰数)
- 11个让你吃惊的 Linux 终端命令
- 虚函数和纯虚函数的区别
- 七牛云储存理解
- Rotional Rose2007安装及激活详细攻略
- Codeforces 659A Round House【水题,细节】
- test
- 回朔法浅析
- Eclipse闪退/打不开/无法启动/一闪而过打解决方法
- Android下使用Protobuf进行序列化
- JavaScript浏览器对象
- generator 生成杨辉三角