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
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’
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
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.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs