0

UILバージョン1.8.0を使用してTwitterプロファイル画像のURLをロードする: http ://api.twitter.com/1/users/profile_image/smashingmag.jpg?size = bigger

ディスクとメモリキャッシュ付き。画像の読み込みと、302リダイレクトに伴うHTMLのディスクキャッシュファイルへの保存に失敗しています。画像が正常に読み込まれたりデコードされたりすることはありません(SimpleImageLoadingListenerのonLoadingFailedメソッドがすべてのTwitterプロファイル画像のURLに対して呼び出されます)。誰でもUILで簡単なTwitter画像のURLをロードできますか?

そのURLのキャッシュファイルの内容は次のとおりです。

cat / mnt / sdcard / MyCache / CacheDir / 1183818163

<html><body>You are being <a href="https://si0.twimg.com/profile_images/3056708597/6438618743e2b2d7d663fd43412bdae8_bigger.png">redirected</a>.</body></html>

これが私の設定です:

File cacheDir = StorageUtils.getOwnCacheDirectory(FrequencyApplication.getContext(), "MyCache/CacheDir");

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
    .cacheInMemory()
    .cacheOnDisc()
    .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
    .build();

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(FrequencyApplication.getContext())
    .memoryCacheExtraOptions(480, 800)
    .threadPoolSize(20)
    .threadPriority(Thread.MIN_PRIORITY)
    .offOutOfMemoryHandling()
    .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
    .discCache(new TotalSizeLimitedDiscCache(cacheDir, 30 * 1024 * 1024))
    .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
    .imageDownloader(new BaseImageDownloader(MyApplication.getContext(), 20 * 1000, 30 * 1000))
    .tasksProcessingOrder(QueueProcessingType.FIFO)
    .defaultDisplayImageOptions(defaultOptions)
    .build();
ImageLoader.getInstance().init(config);
4

1 に答える 1

4

HttpURLConnectionHTTPからHTTPSへのリダイレクトを自動的に処理できないようです(リンク)。次のlibバージョンで修正します。

今のところ修正-拡張BaseImageDownloaderして構成に設定します。

public class MyImageDownloader implements BaseImageDownloader {
    @Override
    protected InputStream getStreamFromNetwork(URI imageUri, Object extra) throws IOException {
        HttpURLConnection conn = (HttpURLConnection) imageUri.toURL().openConnection();
        conn.setConnectTimeout(connectTimeout);
        conn.setReadTimeout(readTimeout);
        conn.connect();
        while (conn.getResponseCode() == 302) { // >=300 && < 400
            String redirectUrl = conn.getHeaderField("Location");
            conn = (HttpURLConnection) new URL(redirectUrl).openConnection();
            conn.setConnectTimeout(connectTimeout);
            conn.setReadTimeout(readTimeout);
            conn.connect();
        }
        return new FlushedInputStream(conn.getInputStream(), BUFFER_SIZE);
    }
}
于 2013-03-05T15:05:45.150 に答える