Question

When I click a link, the amazon file is downloading fine. I have thousands of pdf files in amazon. Now mongoid id as the name of that amazon files. When I download the the files its save with that id's. But I would like to rename the file before save that file to local. I have name field in my mongoid.

include Mongoid::Paperclip

has_mongoid_attached_file :profile_doc

when I link a like this controller action will call

def download 
  if @company.send(doc).exists?
    redirect_to @company.send(doc).expiring_url
  else
    respond_with_error(:not_found)
  end
end

How I rename the file when download the file. now file is downloading like this 50sfdkkmzd.pdf I would like to save name.pdf.

Thanks for your time.

Was it helpful?

Solution

try this, it should work fine

def download
  if @company.send(doc).exists?
    data = open(@company.send(doc).expiring_url)
    send_data data.read, :filename => "name.pdf", :type => data.content_type
  else
    respond_with_error(:not_found)
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top