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,