Re: Determining if an image exists
Re: Determining if an image exists
- Subject: Re: Determining if an image exists
- From: Arturo Perez <email@hidden>
- Date: Thu, 17 Feb 2005 13:34:35 -0500
To avoid loading the whole image do an HTTP HEAD request.
David Griffith wrote:
Hi Colin,
That's the sort of solution I was looking for. I wonder if there is a way
to do it without having to load the image down. I'll have to research it a
little more and see..
Thanks,
David.
Hi David,
I'm not sure if this is what you're looking for, but off the top of my
head, here's a suggestion.
If already have a URL to your resource, you can always instantiate a
URL object for it, open a connection, and then check the status code
that is returned from the Web server. Assuming the images are served up
by the Web server, I assume you'll get a 404 (file not found) if the
image doesn't actually exist, and you should get a 200 if everything
was OK. The downside to this approach--as far as I know--is that you
have to actually connect to the server and pull the image down just to
check if it's there. Here's some sample code:
String imageURL; // Assume this exists and always begins with http://
URL urlForImage = new URL(imageURL);
HttpURLConnection connection = (HttpURLConnection)
urlForImage.openConnection();
if (connection.getResponseCode() == 200)
// The image exists on the Web server.
else
// Do something else.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden