Creating temporary files in Heroku

Viewed 32184

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 the end of file signal from the listener, I upload the file to Amazon S3 servers. But, until the end of file signal is received, is it possible to save the file content as a temporary file in Heroku?

3 Answers

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

Related