Creating temporary files in Heroku

前端 未结 3 1182
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 07:33

I have an app hosted @ Heroku. The app depends on some feeds which are fetched using a socket listener. The socket listener gets one line of XML per second. Once I detect th

3条回答
  •  攒了一身酷
    2020-12-05 07:43

    With the newer Heroku-16 stack, you are able to write to both the root and to /tmp

    Try writing to root with

    f = File.new("filename.txt", 'w')
    f << "hi there"
    f.close
    
    Dir.entries(Dir.pwd) # see your newly created file
    

    Or to /tmp with

    f = File.new("tmp/filename.txt", 'w')
    f << "hi there"
    f.close
    
    Dir.entries(Dir.pwd.to_s + ("/tmp"))
    

    You will see your new file among those listed in both cases

    Also try running heroku restart to see your newly created files disappear! This is expected, as heroku storage is ephemeral (will be deleted when the app restarts) - so don't rely on it for anything more than (very) temporary storage

提交回复
热议问题