我目前正在使用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"];
该代码在模拟器中运行并从模拟器的图片库上传文件时运行良好,因为我使用的是快速以太网连接.然而,在iPhone上 Select 用iPhone拍摄的图像时,相同的代码会超时.所以,我try 了一下,从网上保存了一张小图片,并试图上传,这很管用.
这让我相信iPhone拍摄的大图在有点慢的3G网络上超时了.有没有办法在发送之前压缩/调整iPhone图片的大小?