I am trying to send data from a remote file attachment....
-------
attachment[''url''] =
"http://www.mydomain.com/resource/download/54643"
I wrote a class RemoteFile < ::Tempfile to fetch to remote data
------
remote_file = RemoteFile.new(attachment[''url''] )
so, I get a tempfile
>> #<File:/var/folders/NK/NKfWCW3eEVCg0ERnpPsnME+++TI/-Tmp-/
93806edfbb0daf7303347d7faaffc2d0f5b22a1d20100914-5545-1y66mt8-0>
now I would like to pass the content of this temp file as a base64
value
...
ticketing_xml << "<value><base64>#{ tmp_data
}</base64></value>"
...
how should I do write the tmp_data ?
should I use : open(remote_file ).read
thanks for your suggestions
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2010-Sep-14 17:39 UTC
Re: how to send raw data from a temp file as a base64 value ?
> I am trying to send data from a remote file attachment.... > ------- > attachment[''url''] = "http://www.mydomain.com/resource/download/54643" > > I wrote a class RemoteFile < ::Tempfile to fetch to remote data > ------ > remote_file = RemoteFile.new(attachment[''url''] ) > so, I get a tempfile >>> #<File:/var/folders/NK/NKfWCW3eEVCg0ERnpPsnME+++TI/-Tmp-/ > 93806edfbb0daf7303347d7faaffc2d0f5b22a1d20100914-5545-1y66mt8-0> > > now I would like to pass the content of this temp file as a base64 > value > ... > ticketing_xml << "<value><base64>#{ tmp_data }</base64></value>" > ... > > how should I do write the tmp_data ? > > should I use : open(remote_file ).readSure. If these remote files are big, your Rails processes are going to eat a lot of ram. Instead of reading things into a temp file first, look into open-uri so you can simply read it directly from the remote host into your xml string... -philip -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Philip, this is better .. it seems a little bit more complicated that I thought I need to get a file that I download from this url.... this not the file url, but an html page to download the file attachment[''url''] :: "http://www.pivotaltracker.com/resource/download/ 579633" and then pass the encoded content of the downloaded file as data into the xml , so it''ll become an attachment for another ticketing system.... =>, the open(remote_file ).read doesn''t give me the file, but the html... so, I need to to : 1 - ''execute'' http://www.pivotaltracker.com/resource/download/579633 to get and store the file locally 2- read the file locally , encode it and pass the content as a value in the xml any idea on how to do that ? On 14 sep, 19:39, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > I am trying to send data from a remote file attachment.... > > ------- > > attachment[''url''] = "http://www.mydomain.com/resource/download/54643" > > > I wrote a class RemoteFile < ::Tempfile to fetch to remote data > > ------ > > remote_file = RemoteFile.new(attachment[''url''] ) > > so, I get a tempfile > >>> #<File:/var/folders/NK/NKfWCW3eEVCg0ERnpPsnME+++TI/-Tmp-/ > > 93806edfbb0daf7303347d7faaffc2d0f5b22a1d20100914-5545-1y66mt8-0> > > > now I would like to pass the content of this temp file as a base64 > > value > > ... > > ticketing_xml << "<value><base64>#{ tmp_data }</base64></value>" > > ... > > > how should I do write the tmp_data ? > > > should I use : open(remote_file ).read > > Sure. If these remote files are big, your Rails processes are going to eat a lot of ram. > > Instead of reading things into a temp file first, look into open-uri so you can simply read it directly from the remote host into your xml string... > > -philip-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2010-Sep-15 16:13 UTC
Re: Re: how to send raw data from a temp file as a base64 value ?
On Sep 14, 2010, at 3:00 PM, Erwin wrote:> Thanks Philip, this is better .. it seems a little bit more > complicated that I thought > > I need to get a file that I download from this url.... this not the > file url, but an html page to download the file > attachment[''url''] :: "http://www.pivotaltracker.com/resource/download/ > 579633" > > and then pass the encoded content of the downloaded file as data > into the xml , so it''ll become an attachment for another ticketing > system.... > > =>, the open(remote_file ).read doesn''t give me the file, but the > html... > > so, I need to to : > 1 - ''execute'' http://www.pivotaltracker.com/resource/download/579633 > to get and store the file locallyI''m not understanding what this step means... I''ve never used pivotaltracker though.. does going to that page result in a file being downloaded? Is the download the HTTP response? Or triggered somehow else? If it''s the response open-uri should be able to handle it. I don''t recall how well open-uri handles redirects so double check that. -p> 2- read the file locally , encode it and pass the content as a value > in the xml > > > any idea on how to do that ? > > > > > > On 14 sep, 19:39, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: >>> I am trying to send data from a remote file attachment.... >>> ------- >>> attachment[''url''] = "http://www.mydomain.com/resource/download/54643" >> >>> I wrote a class RemoteFile < ::Tempfile to fetch to remote data >>> ------ >>> remote_file = RemoteFile.new(attachment[''url''] ) >>> so, I get a tempfile >>>>> #<File:/var/folders/NK/NKfWCW3eEVCg0ERnpPsnME+++TI/-Tmp-/ >>> 93806edfbb0daf7303347d7faaffc2d0f5b22a1d20100914-5545-1y66mt8-0> >> >>> now I would like to pass the content of this temp file as a base64 >>> value >>> ... >>> ticketing_xml << "<value><base64>#{ tmp_data }</base64></value>" >>> ... >> >>> how should I do write the tmp_data ? >> >>> should I use : open(remote_file ).read >> >> Sure. If these remote files are big, your Rails processes are going to eat a lot of ram. >> >> Instead of reading things into a temp file first, look into open-uri so you can simply read it directly from the remote host into your xml string... >> >> -philip > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Philip this url is a route to Pivotal web app... when I use "http://www.pivotaltracker.com/resource/download/579633" in my browser, I get a corresponding file attachment downloaded... so, this is an url to Pivotal web app, which execute the action :download in the controller Resource send the file .... which open in my browser so I cannot use this url as a file location url (with open-uri ) and I don''t get the file location ... seems to be redirected to an amazon S3 location where the file is located.... ( yes, the response is You have been redirected blah blah) On 15 sep, 18:13, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Sep 14, 2010, at 3:00 PM, Erwin wrote: > > > > > > > Thanks Philip, this is better .. it seems a little bit more > > complicated that I thought > > > I need to get a file that I download from this url.... this not the > > file url, but an html page to download the file > > attachment[''url''] :: "http://www.pivotaltracker.com/resource/download/ > > 579633" > > > and then pass the encoded content of the downloaded file as data > > into the xml , so it''ll become an attachment for another ticketing > > system.... > > > =>, the open(remote_file ).read doesn''t give me the file, but the > > html... > > > so, I need to to : > > 1 - ''execute''http://www.pivotaltracker.com/resource/download/579633 > > to get and store the file locally > > I''m not understanding what this step means... I''ve never used pivotaltracker though.. does going to that page result in a file being downloaded? Is the download the HTTP response? Or triggered somehow else? If it''s the response open-uri should be able to handle it. I don''t recall how well open-uri handles redirects so double check that. > > -p > > > > > 2- read the file locally , encode it and pass the content as a value > > in the xml > > > any idea on how to do that ? > > > On 14 sep, 19:39, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: > >>> I am trying to send data from a remote file attachment.... > >>> ------- > >>> attachment[''url''] = "http://www.mydomain.com/resource/download/54643" > > >>> I wrote a class RemoteFile < ::Tempfile to fetch to remote data > >>> ------ > >>> remote_file = RemoteFile.new(attachment[''url''] ) > >>> so, I get a tempfile > >>>>> #<File:/var/folders/NK/NKfWCW3eEVCg0ERnpPsnME+++TI/-Tmp-/ > >>> 93806edfbb0daf7303347d7faaffc2d0f5b22a1d20100914-5545-1y66mt8-0> > > >>> now I would like to pass the content of this temp file as a base64 > >>> value > >>> ... > >>> ticketing_xml << "<value><base64>#{ tmp_data }</base64></value>" > >>> ... > > >>> how should I do write the tmp_data ? > > >>> should I use : open(remote_file ).read > > >> Sure. If these remote files are big, your Rails processes are going to eat a lot of ram. > > >> Instead of reading things into a temp file first, look into open-uri so you can simply read it directly from the remote host into your xml string... > > >> -philip > > > -- > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Sep-15 17:17 UTC
Re: Re: how to send raw data from a temp file as a base64 value ?
I maybe am not understanding what you need, but if you are trying to do this
where you have tmp_data in memory and need to encode tmp_data
ticketing_xml << "<value><base64>#{ tmp_data
}</base64></value>"
Then do
require ''base64''
ticketing_xml << "<value><base64>#{
Base64.encode64(tmp_data)
}</base64></value>"
On Wed, Sep 15, 2010 at 11:13 AM, Philip Hallstrom
<philip-LSG90OXdqQE@public.gmane.org> wrote:
>
> On Sep 14, 2010, at 3:00 PM, Erwin wrote:
>
> > Thanks Philip, this is better .. it seems a little bit more
> > complicated that I thought
> >
> > I need to get a file that I download from this url.... this not the
> > file url, but an html page to download the file
> > attachment[''url''] ::
"http://www.pivotaltracker.com/resource/download/
> > 579633"
> >
> > and then pass the encoded content of the downloaded file as data
> > into the xml , so it''ll become an attachment for another
ticketing
> > system....
> >
> > =>, the open(remote_file ).read doesn''t give me the
file, but the
> > html...
> >
> > so, I need to to :
> > 1 - ''execute''
http://www.pivotaltracker.com/resource/download/579633
> > to get and store the file locally
>
> I''m not understanding what this step means... I''ve never
used
> pivotaltracker though.. does going to that page result in a file being
> downloaded? Is the download the HTTP response? Or triggered somehow else?
> If it''s the response open-uri should be able to handle it. I
don''t recall
> how well open-uri handles redirects so double check that.
>
> -p
>
>
> > 2- read the file locally , encode it and pass the content as a value
> > in the xml
> >
> >
> > any idea on how to do that ?
> >
> >
> >
> >
> >
> > On 14 sep, 19:39, Philip Hallstrom
<phi...-LSG90OXdqQE@public.gmane.org> wrote:
> >>> I am trying to send data from a remote file attachment....
> >>> -------
> >>> attachment[''url''] =
"http://www.mydomain.com/resource/download/54643"
> >>
> >>> I wrote a class RemoteFile < ::Tempfile to fetch to remote
data
> >>> ------
> >>> remote_file =
RemoteFile.new(attachment[''url''] )
> >>> so, I get a tempfile
> >>>>>
#<File:/var/folders/NK/NKfWCW3eEVCg0ERnpPsnME+++TI/-Tmp-/
> >>>
93806edfbb0daf7303347d7faaffc2d0f5b22a1d20100914-5545-1y66mt8-0>
> >>
> >>> now I would like to pass the content of this temp file as a
base64
> >>> value
> >>> ...
> >>> ticketing_xml << "<value><base64>#{
tmp_data }</base64></value>"
> >>> ...
> >>
> >>> how should I do write the tmp_data ?
> >>
> >>> should I use : open(remote_file ).read
> >>
> >> Sure. If these remote files are big, your Rails processes are
going to
> eat a lot of ram.
> >>
> >> Instead of reading things into a temp file first, look into
open-uri so
> you can simply read it directly from the remote host into your xml
string...
> >>
> >> -philip
> >
> > --
> > 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> > For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> >
>
> --
> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.