我目前正在iOS上使用Imgur将图像上传到服务器,代码如下:
NSData* imageData = UIImagePNGRepresentation(image);
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SBTempImage.png"];
[imageData writeToFile:fullPathToFile atomically:NO];
[uploadRequest setFile:fullPathToFile forKey:@"image"];
Run Code Online (Sandbox Code Playgroud)
代码在模拟器中运行并从模拟器的照片库上传文件时工作正常,因为我在快速以太网连接上.但是,在选择使用iPhone拍摄的图像时,相同的代码会在iPhone上超时.所以,我尝试通过从网络上保存一个小图像并试图上传它,这是有效的.
这让我相信iPhone拍摄的大图像会在有点慢的3G网络上超时.有没有办法在发送之前压缩/调整iPhone的图像大小?
谢谢!