如何使用载波向用户发送文件? [英] How to send file to user with carrierwave?
本文介绍了如何使用载波向用户发送文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的旧代码,将文件发送到浏览器:
Here's my old code to sends a file to the browser:
def show
send_file File.join(Rails.root, 'tmp', 'price.xls')
end
但是最近我发现tmp文件夹不能用作Heroku上的永久存储,所以我决定将文件移至AWS S3。
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.
到目前为止:
def show
uploader = PriceUploader.new
uploader.retrieve_from_store!('price.xls')
end
现在,如何将文件发送到浏览器?
Now, how do I send the file to the browser?
更新
我故意没有挂载上传器
推荐答案
弄清楚了。
def show
uploader = PriceUploader.new
uploader.retrieve_from_store!('price.xls')
uploader.cache_stored_file!
send_file uploader.file.path
end
这篇关于如何使用载波向用户发送文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文