Android-Universal-Image-Loader
Android-Universal-Image-Loader copied to clipboard
Dynamic URL when use UIL
a question about the method displayImage(url, ..); in the UIL, we use the url to check whether there is cache in memory or on disk, and we also use the url to get http image if there is not any. Here is my question: what if the url is dynamic, every time the url is different, however, the target image is same. so we maybe save one same image on the disk for every time. what should we do to avoid this?
How can we define that some URLs reference the same image? Can we define it by URL before HTTP request?
you can cut off your URL ,I guess your URL may lik http://www.google.com/your_server_disk/image.jpg you can use your_server_dish/image.jpg as the key to save and get your image
@nostra13 @freecsdn No, we can not define the URL before HTTP request. I post request to the server, then I get a dynamic URL to the image. For example, I post request three times, then I may get three URL, like this: http://www.abcdefg.com/111?aaa http://www.abcdefg.com/111?bbb http://www.abcdefg.com/111?ccc however, the aboving three URLs point to the same picture, if I use the method displayImage(url, ...), I can get three same pictures in my disk cache. Is there any method to avoid this ? the substring before "?" is same, however, If I pass the substring(like http://www.abcdefg.com/111), I just can not get the image at all. Is there any method to solve this problem.
i know he what want , he want open all photos in a folder from site (dont want import photos name) , like : www.site.com/mypictures/ i dont know can do it or no , but ths is very good you can change photo and update gallery when you want :+1: :+1: nostra1 :+1: we can do it ?
Dynamic URL support is also needed in case of Amazon S3 secured URL for images, Where URL's are generated dynamically and valid for defined moment, This library for iOS does it nicely by having a mechanism for cacheKeyFilter (meaning custom cacheKey) https://github.com/rs/SDWebImage#using-cache-key-filter
cc @badnamess , @nostra13
Please let me know, I want to confirm do UIL support this kind of feature.
Thanks Rahul
I have this issue too when loading images from a web service where an auth token is part of the URL. This token changes each time the app is launched, so the URL is always different.
What I would like to be able to do is to have an overloaded version of the displayImage method that takes an extra argument for the cache key. Something along these lines:
ImageLoader.getInstance().displayImage(url, imageView, cacheKey);
And that would override the default cache key, thus allowing me to specify a custom one.
I haven't looked at the code for UIL, so I don't know if this would be a practical solution. It's just a thought :)
@newtonker did you have good solution your problem above?
How did you resolve this?
Since the URIs are different,how do you know that they are the same image ?
because I can see that what is different is just an authentication Token.
I have resolved this my extending the memory cache and pass all uses of the key through a function that strips out the bit that changes.
public class ImageLoaderMemoryCache extends BaseMemoryCache {
/**
* Removes Token query parameter, because on some urls it can
change on every request, like in this example: *
* https://filerepository.itslearning.com/4c2ce282-2028-4465-bb9e-5b8edd5b3fff?Token=HRsGABQIAADXVZ1ZAAAAACAApDS1H6qoBW9A6prPAeeVN3IHoP3DG63FMqQMhYy0inkAAA%3d%3d&Download=1 / public static String cleanKey(String key) { return key.replaceAll("Token=.&", ""); }
@Override
protected Reference<Bitmap> createReference(Bitmap value) {
return null;
}
@Override
public Bitmap get(String key) {
return super.get(cleanKey(key));
}
@Override
public boolean put(String key, Bitmap value) {
return super.put(cleanKey(key), value);
}
@Override
public Bitmap remove(String key) {
return super.remove(cleanKey(key));
}
}
On 24 August 2017 at 12:54, Edwin_C [email protected] wrote:
Since the URIs are different,how do you know that they are the same image ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nostra13/Android-Universal-Image-Loader/issues/850#issuecomment-324602528, or mute the thread https://github.com/notifications/unsubscribe-auth/AFZvMJXU6RC0Dnl-TBhflw5JYXwH_b7kks5sbVZkgaJpZM4DKCX6 .
Great! You make yourself more excellent. It also makes me get benefits.
@alexladerman I wonder about your solution. your solution is getting the clear key, so you can strip off the key on MemoryCache. How about the DiskCache and image downloading task? I imagine the DiskCache is using the same clear key passing from MemoryCache above. But what happens if Image was never cached in both MemoryCache and DiskCache? we have to download it from the network, but the key was stripped off, so I don't think we are able to download the image.