I would like to check if URL given by user is image (jpg, png, gif). First idea: check only file extension in URL. Second idea: get this resource from server (by http get) and load into some Java picture library to get info if is it image (seriously disadvantage: slow). Or maybe yet another solution?
Asked
Active
Viewed 5,005 times
1 Answers
16
You should use HTTP HEAD, not a full GET. This should include the Content-Type as known by the server. You could of course test the extension first, and only do the expensive/slow HTTP roundtrip if it's inconclusive.

unwind
- 391,730
- 64
- 469
- 606
-
3and here is the code to make HEAD http://stackoverflow.com/questions/4177864/checking-a-url-exist-or-not/4177885#4177885 – jmj Jan 25 '11 at 13:24