ios - iOS和S3:使用网址从S3下载图片

标签 ios amazon-s3

是否可以在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/

相关文章:

ios - 无法将类型 'UILabel!' 的值转换为预期参数 'type inout String'

iOS:如何模仿 'to' 字段?

ios - 最小化 header 导入

amazon-web-services - 'root account credentials' 和 'IAM user credentials' 之间的差异

amazon-web-services - 配置 aws cli 使用 fakes3

ios - 重用 View Controller 及其 ivars、scrollviews、tableview

amazon-s3 - Amazon Elastic MapReduce - 从 S3 到 DynamoDB 的大量插入非常慢

amazon-web-services - 使用aws客户端仅从单个目录复制s3文件(非递归)

node.js - Node JS AWS S3 文件上传。如何获取公共(public) URL 响应

ios - 词典词典