vell
2014-Mar-26 02:29 UTC
Heroku | Rails 4 | Ruby 2.0 - send_file not presenting file for download in the browser
Hello all,
I am have an app that is hosted on heroku (rails 4 | ruby 2.0) that I am using
paperclip-dropbox to upload attachments to a blog. I have created a download
link for people who read the blog to be able to download the attachments but I
am not able to get the file to actually download via the browser. I am curious
if anyone knows what could be the issue.
My process is I download the file locally, using HTTParty.get, to public/images
and then attempt to present the file to the user to download. Getting the file
to download is working without issue. But getting the browser to present the
file is my problem.
I am looking for any help on what I could do to figure out what I may be doing
incorrectly.
Here is what I currently have:
app/controllers/blog_attachments.rb
before_action :set_blog_attachment, only: [:download]
def download
download_file(@blog_attachment)
send_file("#{Rails.root}/public/blog_attachments/#{@blog_attachment.document_file_name}",
filename: @blog_attachment.document_file_name,
type: @blog_attachment.document_content_type,
stream: true,
disposition: 'inline')
respond_to do |format|
format.js {}
end
end
private
def download_file(file)
File.open("#{Rails.root}/public/blog_attachments/#{file.document_file_name}",'wb')
do |f|
f.write HTTParty.get(file.document.url).parsed_response
end
end
# Use callbacks to share common setup or constraints between actions.
def set_blog_attachment
@blog_attachment = BlogAttachment.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list
through.
def blog_attachment_params
params[:blog_attachment]
end
app/views/blogs/show.html.erb
<% for attachment in @blog.blog_attachments %>
<%= link_to attachment.document_file_name,
download_blog_attachments_path(id: attachment.id), remote: true, method: :get
%>
<% end %>
Any help is greatly appreciated.
Thanks,
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/7FCB0CB0-9BFA-4F9F-9CD2-700EC40B0ECC%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
