开发者

Heroku: Serving Large Dynamically-Generated Assets Without a Local Filesystem

开发者 https://www.devze.com 2022-12-09 05:39 出处:网络
I have a question about hosting large dynamically-generated assets and Heroku. My app will offer bulk download of a subset of its underlying data, which will consist of a large file (>100 MB) generat

I have a question about hosting large dynamically-generated assets and Heroku.

My app will offer bulk download of a subset of its underlying data, which will consist of a large file (>100 MB) generated once every 24 hours. If I were running on a server, I'd just write the file into the public directory.

But as I u开发者_如何学Gonderstand it, this is not possible with Heroku. The /tmp directory can be written to, but the guaranteed lifetime of files there seems to be defined in terms of one request-response cycle, not a background job.

I'd like to use S3 to host the download file. The S3 gem does support streaming uploads, but only for files that already exist on the local filesystem. It looks like the content size needs to be known up-front, which won't be possible in my case.

So this looks like a catch-22. I'm trying to avoid creating a gigantic string in memory when uploading to S3, but S3 only supports streaming uploads for files that already exist on the local filesystem.

Given a Rails app in which I can't write to the local filesystem, how do I serve a large file that's generated daily without creating a large string in memory?


${RAILS_ROOT}/tmp (not /tmp, it's in your app's directory) lasts for the duration of your process. If you're running a background DJ, the files in TMP will last for the duration of that process.

Actually, the files will last longer, the reason we say you can't guarantee availability is that tmp isn't shared across servers, and each job/process can run on a different server based on the cloud load. You also need to make sure you delete your files when you're done with them as part of the job.

-Another Heroku employee


Rich,

Have you tried writing the file to ./tmp then streaming the file to S3?

-Blake Mizerany (Heroku)

0

精彩评论

暂无评论...
验证码 换一张
取 消