• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Determining if an image exists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining if an image exists


  • Subject: Re: Determining if an image exists
  • From: David Griffith <email@hidden>
  • Date: Thu, 17 Feb 2005 18:22:14 +0100

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.
>
> Alternatively, if your app is guaranteed to live on the same box as the
> Web server, you could simply open a File object to the location of your
> URL relative to the document root, and use the exists() method to see
> if it's actually there. This approach is more brittle because it
> assumes that your application and Web server are closely coupled.
>
> I hope that helps,
>
> Colin
>
>
> On Thursday, February 17, 2005, at 10:02  AM, David Griffith wrote:
>
>> Hi all,
>>
>> Just wondered if anyone has a simple approach to use Java in
>> WebObjects to determine if an image (or file) exists at a URL.
>>
>> What I¹m doing is fairly simple, I want to display up to 4 images
>> which have dynamic URL¹s.  I want to check first if the image (URL)
>> actually exists on the web server.  If not, I don¹t want to display > it.
>>
>> Any suggestions?
>>
>> Kind regards,
>> David. _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list      (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> email@hidden
>>
>> This email sent to email@hidden
> ---
> Colin Clark
> Dynamic Web and Database Development Lead,
> Resource Centre for Academic Technology,
> University of Toronto
>


 _______________________________________________
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

  • Follow-Ups:
    • Re: Determining if an image exists
      • From: Arturo Perez <email@hidden>
References: 
 >Re: Determining if an image exists (From: Colin Clark <email@hidden>)

  • Prev by Date: Re: Determining if an image exists
  • Next by Date: Re: Determining if an image exists
  • Previous by thread: Re: Determining if an image exists
  • Next by thread: Re: Determining if an image exists
  • Index(es):
    • Date
    • Thread