简体   繁体   中英

Running into problems with creating a file on Heroku (Rails)

So I have a user model and upon a user's registration I need to generate a file with some specific user information in it. Heroku is not allowing me to do that. Is there any other option besides generating the file and writing it to an S3 bucket and referencing it from there.

Heroku's file system is read-only. The only exception is the tmp dir, but that's, well, temporary. S3 is a common solution. Another possibility is saving that "file" to the database (use a "text" column in your migration). You could also use some document store, such as CouchDB or MongoDB and store your "file" there. There are several Heroku add-ons for Couch and Mongo that even offer a free tier.

On the Cedar stack, the filesystem is ephemeral, which means that the filesystem only exists for the duration of the dyno (which is an unknown and unpredictable amount of time).

On the older stacks, only /tmp is writable, and again is ephemeral.

Therefore, to produce a file and export it you need to think about how you need to deliver the file.

If it's for a download later on, can you produce the file from the database at any time (thus saving the need for a file to be written out at all).

If it's for download now, stream it back to the end user.

It it's for export to S3, do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM