Test For JPEG Image Over HTTP

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/image.jpg’)

end

Neil Charlton wrote:

if open(‘http://example.net/path/to/image.jpg’)

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs