Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to convert a URL into a filename

I'm writing an asynchronous image downloader for Android and was just wondering, given an arbitary URL such as:

http://www.android.com/images/brand/droid.gif

What would be the best way to convert the unique url to a filename. I thought about simply splitting the url and grabbing the last section, but I want the filename to be representative of the whole URL. The other alternatives I thought were replacing all the forward slashes with underscores or simply hashing the whole URL and storing this.

If anyone has any ideas I'd love to hear them!

Thanks

like image 702
Ljdawson Avatar asked Jan 29 '12 17:01

Ljdawson


People also ask

How do I get the filename in a URL?

The filename is the last part of the URL from the last trailing slash. For example, if the URL is http://www.example.com/dir/file.html then file. html is the file name.


1 Answers

In case, usually uses MD5 hash. but I suggest to use 'aquery' library. In library you can simply download Image asynchronous and put it to view. It also support disk cache, memory cache simply.

like image 82
lulumeya Avatar answered Oct 11 '22 16:10

lulumeya