Kad Kerforn wrote:
> In my app, I have an URL to download a file from a remote site ,  when
> using this URL in a browser I download the file...
> 
> "http://www.anotherdomain.com/resource/download/579633";
> 
> but I need to to get the content of this file within my app , as I
> must encode it and transfer to another app
> 
> if I use this url with open-uri, I get the html page, not the file
> itself......
> should I execute the download within my app ( how) and store it in a
> temp file
> then open it and encode ..
> 
> how should I proceed to make it as simple as possible ?
> 
> thanks for your feedback

You are on the right track, but if OpenURI is pulling down an HTML page 
then you may be pointing at the wrong place. With that sorted all you 
need to do is something like the following:

require 'open-uri'
file = Tempfile.new
file.binmode
open(url, headers) { |data| file.write data.read }

That will give you your content in the file variable, and then you can 
encode away.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to