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?
A URL is a web address that specifies location. Therefore, an image URL is a web address that specifies the location of an image.
Every image needs a URL because every image is a unique image. mysite.com/img/potato.png and mysite.com/img/apple.png are 2 separate images on my website for example.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With