objective-c - ios 存储图片到七牛时文件变大?
世界只因有你
世界只因有你 2017-05-02 09:19:47
0
1
722

1.保存图片到七牛中,但是如果选择的图片是100kb,保存到七牛后 空间会变为2M。由于图片变大,下载缓慢,且使用时内存大

2.保存到七牛的代码

// 图片转换为data
NSData *imageData = UIImagePNGRepresentation(weakself.coverImage);
if (imageData == nil) {
   imageData = UIImageJPEGRepresentation((UIImage *)weakself.coverImage, 1.0);
}
//将图片data保存到本地

NSString *fileName = [NSString stringWithFormat:@"%@_%@", [[NSProcessInfo processInfo] globallyUniqueString], @"image.png"];

NSURL *fileUrl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:fileName]];
NSError *error = nil;
[file writeToURL:fileUrl options:NSDataWritingAtomic error:&error];
tempFile.path 为选择图片保存到本地后的地址
keyup 为文件名
g_token 为上传的token
[_upManager putFile:tempFile.path key:keyUp token:g_token complete: ^(QNResponseInfo *i, NSString *k, NSDictionary *resp) {
         key = k;
         info = i;
 } option:opt];

3.尝试将直接putdata到七牛,不将data保存到本地 但是效果依旧。。。

世界只因有你
世界只因有你

reply all(1)
给我你的怀抱

Are you using Qiniu’s sdk? Or did you write it yourself? The size of the file uploaded by Qiniu SDK will not change. Can you provide more detailed information? Can you provide the uploaded reqestid?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!