I use fresco as my app image loader.
My app client upload local image files to remote server. After upload successfully, in order to save bandwidth and avoid download images again from remote server, I use the following method to manually add a local file to fresco image cache.
public static void setCachedImageOnDisk(String key, File file) {
if (key == null || file == null) {
return;
}
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(ImageRequest.fromUri(key));
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
Fresco.getImagePipelineFactory().getMainDiskStorageCache()
.insert(cacheKey, WriterCallbacks.from(inputStream));
Fresco.getImagePipelineFactory().getSmallImageDiskStorageCache()
.insert(cacheKey, WriterCallbacks.from(inputStream));
Log.d(TAG, "set key on disk " + key);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
The key
above is the full URL of the image. From the debug output, it's a valid image URL. But it doesn't work, my android app client still need to download the image again. Is something wrong for the key? How fresco use key to track images in its cached directory?