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

前端 未结 2 442
长发绾君心
长发绾君心 2020-12-22 09:42

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 an

相关标签:
2条回答
  • 2020-12-22 09:53

    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.

    0 讨论(0)
  • 2020-12-22 10:02

    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.

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