Creating temporary files in Heroku

前端 未结 3 1184
伪装坚强ぢ
伪装坚强ぢ 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:44

    The documentation on Heroku's read-only file system explains that you can use #{RAILS_ROOT}/tmp but doesn't give any examples for generating a temporary filename. This will guarantee uniqueness of the filename:

    prefix = 'mydata'
    suffix = '.xml'
    Tempfile.new [prefix, suffix], "#{Rails.root}/tmp"
    

    Note that "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."

提交回复
热议问题