是否可以在iOS中使用url从s3下载图像,所以我不必使用s3 sdk?
使用url和NSURLConnection.sendAsynchronousRequest下载图像更加方便,因为我直接获得了url。
我尝试这样做,但始终会收到超时错误。
如果我将网址切换到不在s3中的其他图像,则可以成功下载该图像。
可以直接使用url在网络上查看s3图像。
码:
var urlString = self.thumbnailImageURL
var imgURL: NSURL = NSURL(string: urlString)
var request: NSURLRequest = NSURLRequest(URL: imgURL, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 90)
var urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler:
{(response: NSURLResponse!, data:NSData!,error:NSError!)-> Void in
if let e: AnyObject = error {
println("Image Download Error: \(error.localizedDescription)")
}else{
...
我收到“图像下载错误:请求超时。”
最佳答案
嗨,这是一个很好的问题。
是的,可以在不使用s3库的情况下保存图像。
我可以使用ASIHTTPRequest
提供解决方案。
- (ASIHTTPRequest *)newHttpRequest
{
NSString *path = [MEDispatcher sharedInstance].profileData.picture;
NSURL *url = [[NSURL alloc] initWithString:path];
ASIHTTPRequest *result = [[ASIHTTPRequest alloc] initWithURL:url];
[result setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[url release];
result.timeOutSeconds = MERequestTimeoutInterval;
return result;
}
从URL获取有关图像的数据是微笑请求。作为回应,我解析了有关图像的所有信息。
关于ios - iOS和S3:使用网址从S3下载图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25294970/