Kad Kerforn
2007-Aug-27 11:04 UTC
send_file : downloaded file cannot be open after upload OK
I easily implemented the upload , using the ''attachment_fu'' plugin... I can see and open the uploaded files (a pdf file 60k and a jpeg images 28k) now I try to implement the download action in my document_controller, I wrote : def download @document = Document.find(params[:id]) send_file(@document.full_filename, :filename => URI.encode(@document.filename), :type => @document.content_type, :encoding => ''utf8'', :disposition => ''attachment'', :stream => ''true'', :buffer_size => ''4096'') redirect_back_or_default(home_url) end I got back the downloaded files... but i always get back a 16k whatever it''s pdf or jpeg, and when I try to open them, I got an error : Failed to find PDF header: `%PDF'' not found. for the pdf file and corrupted or not recognized.... what''s wrong in my send_file options note : I am testing locally on localhost -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2007-Aug-27 11:12 UTC
Re: send_file : downloaded file cannot be open after upload OK
On 27 Aug 2007, at 13:04, Kad Kerforn wrote:> I easily implemented the upload , using the ''attachment_fu'' plugin... > I can see and open the uploaded files (a pdf file 60k and a jpeg > images > 28k) > > now I try to implement the download action in my > document_controller, I > wrote : > > def download > @document = Document.find(params[:id]) > send_file(@document.full_filename, > :filename => URI.encode(@document.filename), > :type => @document.content_type, > :encoding => ''utf8'', > :disposition => ''attachment'', > :stream => ''true'', > :buffer_size => ''4096'') > redirect_back_or_default(home_url) > endDon''t redirect at the end of your for one. No new page will be rendered anyway (the user will just get the download dialog). Also don''t make things more complicated than they need to be: def download @document = Document.find(params[:id]) send_file(@document.full_filename, :filename => @document.filename, :type => @document.content_type, :disposition => ''attachment'') end Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kad Kerforn
2007-Aug-27 11:39 UTC
Re: send_file : downloaded file cannot be open after upload
Peter De Berdt wrote:> On 27 Aug 2007, at 13:04, Kad Kerforn wrote: > >> @document = Document.find(params[:id]) >> send_file(@document.full_filename, >> :filename => URI.encode(@document.filename), >> :type => @document.content_type, >> :encoding => ''utf8'', >> :disposition => ''attachment'', >> :stream => ''true'', >> :buffer_size => ''4096'') >> redirect_back_or_default(home_url) >> end > > Don''t redirect at the end of your for one. No new page will be > rendered anyway (the user will just get the download dialog). > > Also don''t make things more complicated than they need to be: > def download > @document = Document.find(params[:id]) > send_file(@document.full_filename, > :filename => @document.filename, > :type => @document.content_type, > :disposition => ''attachment'') > end > > > Best regards > > Peter De BerdtThanks Peter ! up and running well.... btw , are u from SA ? (because of the name...) if yes, be our guest for the coming Rugby World Cup, otherwise sorry, u will not understand that game.... ;-)) -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---