[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Test For JPEG Image Over HTTP

neilc

8/17/2006 8:13:00 AM

Hi

I would like to test for the existence of a .jpg image on a remote
server over HTTP.

I have tried 2 different methods but they are not what I need.

Method 1:

require 'open-uri'
if open('http://example.net/path/to/imag...)

end

--
Posted via http://www.ruby-....

1 Answer

Alex Young

8/17/2006 8:21:00 AM

0

Neil Charlton wrote:
> Hi
>
> I would like to test for the existence of a .jpg image on a remote
> server over HTTP.
>
> I have tried 2 different methods but they are not what I need.
>
> Method 1:
>
> require 'open-uri'
> if open('http://example.net/path/to/imag...)
>
> end
>
require 'net/http'

# Strict existence
def url_exists?(path)
u = URI.parse(path)
h = Net::HTTP.new(u.host, u.port)
r = h.head(u.path)
return Net::HTTPOK === r
end

# Lack of non-existence
def url_found?(path)
u = URI.parse(path)
h = Net::HTTP.new(u.host, u.port)
r = h.head(u.path)
return !(Net::HTTPNotFound === r)
end

--
Alex