Hi, I am uploading a PDF file using paper clip. File get uploaded successfully. If I try to view the file directly from file system it is opening. I have to open the file from application so I have written following code. View Code:- <%= link_to ''View Attachment'', {:action=>"show_attachment", :id=>user.id} %> Controller Code:- def show_attachment @user=User.find(params[:id]) send_data(@user.attachment.url, :type => "application/pdf", :filename => "attachment.pdf", :disposition => ''attachment'') end Whenever I run the application and click on ''View Attachment'' link it opens the pop up which ask for either save it or open it. I click on "OK", it starts to download pdf file but ends with saying "Adobe Reader could not open "attachment-4.pdf" beacuse either it not supported file type or file has been damaged." Can anyone tell me what is the issue? I can see the pdf file from the uploaded location. Thanks, Tushar -- 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-/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.
On 01 Feb 2011, at 14:41, Tushar Gandhi wrote:> I am uploading a PDF file using paper clip. File get uploaded > successfully. If I try to view the file directly from file system it > is > opening. > I have to open the file from application so I have written following > code. > View Code:- > <%= link_to ''View Attachment'', {:action=>"show_attachment", > :id=>user.id} %> > > Controller Code:- > def show_attachment > @user=User.find(params[:id]) > send_data(@user.attachment.url, :type => "application/pdf", > :filename => "attachment.pdf", :disposition => ''attachment'') > end > > Can anyone tell me what is the issue? > I can see the pdf file from the uploaded location.You probably need to use the path instead of the url for sending files: send_data(@user.attachment.path, :type => "application/pdf", :filename => "attachment.pdf", :disposition => ''attachment'') 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-/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.
Hi, Thanks for your reply, but still it is not working. Any other suggestion. Thanks, Tushar -- 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-/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.
On Feb 2, 4:52 am, Tushar Gandhi <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > Thanks for your reply, but still it is not working.send_data expects you to be giving it the actual bytes to send, not a url or a file path. You need to read the file yourself (or use send_file which will take care of that) Fred> > Any other suggestion. > > Thanks, > Tushar > > -- > Posted viahttp://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-/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.