从Amazon S3 A​​FNewtorking加载图像 [英] AFNewtorking loading images from Amazon S3

查看:162
本文介绍了从Amazon S3 A​​FNewtorking加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们只使用AFNetworking加载这样的图片:

We were using AFNetworking only to load images like this:

[thumbnailImage setImageWithURL:_item.thumbnailUrl];

和它工作得很好。但是,现在我们已经将它已停止工作项目的其余部分。这只是显示了背景色。所以,我想用这个和它加载的占位符,但从来没有加载图像。

and it worked fine. But now we've pulled in the rest of the project it has stopped working. It was just showing the background color. So I tried using this and it loads the placeholder but never loads the image.

UIImage* placeholder = [UIImage imageNamed:@"placeholder"];
[thumbnailImage setImageWithURL:_item.thumbnailUrl placeholderImage:placeholder];

我想我也许能看到的问题是什么,所以我尝试:

I thought I might be able to see what the problem was so I tried:

NSURLRequest* urlRequest = [NSURLRequest requestWithURL:_item.thumbnailUrl cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];

[thumbnailImage setImageWithURLRequest:urlRequest placeholderImage:[UIImage imageNamed:@"placeholder"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
    NSLog(@"Loaded Image");
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
{
    NSLog(@"Failed to load Image");
}];

和它似乎不是得到的返回类型,它的预期。它说预期的内容类型image / PNG,得到的二进制/八位字节流我拉着从Amazon S3的形象,所以我不知道如果我过的类型有控制

and it seems that it's not getting the return type that it's expecting. It says Expected content type image/png, got binary/octet-stream I'm pulling the image from Amazon S3 so I don't know if I have control over the type.

推荐答案

我无法更改数据类型,所以我在AFNetworking覆盖了 acceptableContentTypes 方法,通过增加下列文件到我的项目。

I wasn't able to change the data type so I overrode the acceptableContentTypes method in AFNetworking by adding the following files to my project.

AFImageRequestOperation + OctetMIMEType.h

//
//  AFImageRequestOperation+OctetMIMEType.h
//  iQ.fileShare
//
//  Created by Poole, Patrick on 4/25/13.
//
//

#import "AFImageRequestOperation.h"

@interface AFImageRequestOperation (OctetMIMEType)

@end

AFImageRequestOperation + OctetMIMEType.m

//
//  AFImageRequestOperation+OctetMIMEType.m
//  iQ.fileShare
//
//  Created by Poole, Patrick on 4/25/13.
//
//

#import "AFImageRequestOperation+OctetMIMEType.h"

@implementation AFImageRequestOperation (OctetMIMEType)
+ (NSSet *)acceptableContentTypes {
    return [NSSet setWithObjects:@"binary/octet-stream",@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon" @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];
}
@end

这篇关于从Amazon S3 A​​FNewtorking加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆