Alex Young wrote:
> Neil Charlton wrote:
>> if open('http://example.net/path/to/image.jpg')
>> The server where the images are always returns a default page if the 
>> images do not exist so the code above always returns.
>> 
>> What I need is a way to check what is returned is not a html page but is 
>> a .jpg image.
>> 
> 
> Oh.  Try this:
> 
> require 'net/http'
> 
> def url_is_a_jpg(url)
>    u = URI.parse(url)
>    h = Net::HTTP.new(u.host, u.port)
>    r = h.head(u.path)
>    return r.content_type == 'image/jpeg'
> end

Hi Alex

Thanks for your help. I can see what you are doing there unfortunately I 
get the following error

isjpg.rb:7:in `url_is_a_jpg': undefined method `content_type' for 
#<Net::HTTPOK 200 readbody=true> (NoMethodError)

ruby -v is
ruby 1.8.2 (2004-12-25) [x86_64-linux]

Any ideas ?

Thanks
Neil


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