How to send file to user with carrierwave?

江枫思渺然 提交于 2019-12-21 04:16:10

问题


Here's my old code to sends a file to the browser:

def show
  send_file File.join(Rails.root, 'tmp', 'price.xls')
end

But recently I've found out that tmp folder can't be used as a persistent storage on Heroku, so I decided to move the file to AWS S3.

That's what I've got so far:

def show
  uploader = PriceUploader.new
  uploader.retrieve_from_store!('price.xls')
end

Now, how do I send the file to the browser?

upd

I itentionally didn't mount the uploader


回答1:


Figured it out.

def show
  uploader = PriceUploader.new
  uploader.retrieve_from_store!('price.xls')
  uploader.cache_stored_file!

  send_file uploader.file.path
end



回答2:


In my case

# find  uploader ...

send_file(uploader.path,
         filename: uploader.filename,
         type: "application/<some-type>")


来源:https://stackoverflow.com/questions/7193516/how-to-send-file-to-user-with-carrierwave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!