如何生成文件,然后使用 Heroku 进行 zip/压缩?

发布于 2024-09-30 08:01:10 字数 365 浏览 6 评论 0原文

我有点想做与此相反。< /a>

我不想解压缩并将集合文件添加到 S3,而是根据

用户的请求:

  1. 生成一堆 xml 文件
  2. ,用一些图像(托管在 s3 上的预先存在的图像)压缩 xml 文件,
  3. 下载 zip

有谁知道一个好方法吗?做这个?我想我可以在普通机器上管理这个没有问题,但 Heroku 使事情变得有些复杂,因为它有一个只读文件系统。

I sort of want to do the reverse of this.

Instead of unzipping and adding the collection files to S3 I want to

On user's request:

  1. generate a bunch of xml files
  2. zip the xml files with some images (pre-existing images hosted on s3)
  3. download zip

Does anybody know agood way of doing this? I think I could manage this no problem on a normal machine but Heroku complicates things somewhat in that it has a read-only filesystem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2024-10-07 08:01:10

来自只读文件系统的heroku文档:

有两个可写目录:./tmp 和 ./log(在应用程序根目录下)。如果您希望在请求期间暂时删除文件,可以写入类似 #{RAILS_ROOT}/tmp/myfile_#{Process.pid} 的文件名。无法保证该文件在后续请求中会存在(尽管可能存在),因此不应将其用于任何类型的永久存储。

您应该能够非常轻松地将生成的 xml 文件写入 tmp/ 并跟踪名称,下载 s3 文件并将其写入同一目录,然后(也许?)调用 zip 命令:只要输出位于 tmp/ 中,然后使用正确的 mime 类型将文件提供给浏览器以提示下载。我只关心文件大小有多大,以及heroku 是否对 tmp 目录中允许的内容有未记录的限制。特别是因为您仅在单个请求期间执行此操作以进行一次性下载,所以我认为您很有可能能够做到这一点。

编辑:环顾四周,您可能可以使用RubyZip之类的东西来如果您想避免调用系统命令,请创建您的 zip 文件。

From the heroku documentation on the read-only filesystem:

There are two directories that are writeable: ./tmp and ./log (under your application root). If you wish to drop a file temporarily for the duration of the request, you can write to a filename like #{RAILS_ROOT}/tmp/myfile_#{Process.pid}. 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.

You should be able to pretty easily write your generated xml files to tmp/ and keep track of the names, download and write the s3 files to the same directory, and (maybe?) invoke a zip command as long as the output is in tmp/, then serve the file to the browser with the correct mime type to prompt a download. I would only be concerned with how big the filesize is and if heroku has an undocumented limit on what they'll allow in the tmp directory. Especially since you are only performing this action for a one-time download in the duration of a single request, I think you have a good chance of being able to do it.

Edit: Looking around a bit, you might be able to use something like RubyZip to create your zip file if you want to avoid calling system commands.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文