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

前端 未结 1 1074
抹茶落季
抹茶落季 2021-01-03 03:51

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

相关标签:
1条回答
  • 2021-01-03 04:02

    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

    0 讨论(0)
提交回复
热议问题