views:

121

answers:

2

Hi guys, I'm trying to call resources (images, for example.) from my website to avoid constant updates. Thus far, I've tried just using this:

 @sprite.bitmap = Bitmap.new("http://www.minscandboo.com/minscgame/001-Title01.jpg")

But, this just gives "File not found error". What is the correct method for achieving this?

+1  A: 

Try using Net::HTTP to get a local file first:

require 'net/http'

Net::HTTP.start("minscandboo.com") { |http|
  resp = http.get("/miscgame/001-Title01.jpg")
  open("local-game-image.jpg", "wb") { |file|
    file.write(resp.body)
   }
}

# ...

@sprite.bitmap = Bitmap.new("local-game-image.jpg")
John Feminella
A: 

To read a file remotely you can use open-uri (in Ruby's standard library.) Saves having to mess around with Net::HTTP.

require "open-uri"

class Bitmap
  def initialize file
    puts file.read
  end
end

Bitmap.new(open("http://www.minscandboo.com/minscgame/001-Title01.jpg"))

Which outputs the contents of your remote image.

Caius