Copying a file from a URL to local machine

Hello,

In my model, I’d like to be able to copy a remote .jpg file from a URL:

http://<doman.com>/path/picture.jpg

I’d like to copy this to my local machine in my model. What
libraries/calls could I make to make this work?

Any help would be appreciated,

Thanks,

Sam.

Sam D. wrote:

Hello,

In my model, I’d like to be able to copy a remote .jpg file from a URL:

http://<doman.com>/path/picture.jpg

I’d like to copy this to my local machine in my model. What
libraries/calls could I make to make this work?

Any help would be appreciated,

Thanks,

Sam.

Sam,

The following is what I do to send a file from MY DOMAIN to the client:

Note: Substitute your own mime-type. In this case, p.render is a
method of PDF::Writer. If you read a file into an object then it should
do the same thing (I think).

send_data p.render, :filename => “my_pdf_filename.pdf”, :type =>
“application/pdf”

OR…you can do this, but I have read some people have concerns because
it exposes your file location and any other file can subsequently be
received:

send_file( path_and_file_name, :type => "application/pdf")

Hope that helps! I’m not an expert so maybe some of the other more
senior people will have a better answer.

Michael

mmodica at cox dot net

I’d like to copy this to my local machine in my model. What
libraries/calls could I make to make this work?

Do you mean copy the image for a remote server to the server
containing the application or from the application server to a users
local machine?

If it’s the first case you will probably find the net/http and
open-uri libraries useful (they are in the standard lib) in the latter
case see the above post.

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