How can I change the upload directory for paperclip on heroku to /tmp?

被刻印的时光 ゝ 提交于 2019-12-18 17:00:23

问题


I need to upload files and then parse them using paperclip?

Currently it is uploaded in the /system folder, which isn't allowed in heroku.

I don't need the uploads to be persistent...I parse it and then store them.

So I'd like to be able to save into /tmp and then parse, and then let it get blown away later.

Thoughts on how to do this (if I should do this)?


回答1:


Heroku's docs say to use Tempfile.

Well, it says in the doc:

There are two directories that are writeable: ./tmp and ./log (under your application root). If you wish to drop a file temporarily for the duration of the request, you can write to a filename like #{RAILS_ROOT}/tmp/myfile_#{Process.pid}. There is no guarantee that this file will be there on subsequent requests (although it might be), so this should not be used for any kind of permanent storage

Then, if you click on the Adam Wiggins link below that, he says this is available through the Tempfile interface.

Using Tempfile is easy, but your file may not exist if heroku considers read/write file operations different processes.

# tempfile_example.rb
require 'tempfile'

# defaults to Dir::tempdir
x = Tempfile.new('imagefile.png') 

puts x.path

Edit: The Answer

The answer is actually to set :path => " " ... but you were close.... – Angela



来源:https://stackoverflow.com/questions/3136773/how-can-i-change-the-upload-directory-for-paperclip-on-heroku-to-tmp

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