如何生成文件,然后使用 Heroku 进行 zip/压缩?
我有点想做与此相反。< /a>
我不想解压缩并将集合文件添加到 S3,而是根据
用户的请求:
- 生成一堆 xml 文件
- ,用一些图像(托管在 s3 上的预先存在的图像)压缩 xml 文件,
- 下载 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:
- generate a bunch of xml files
- zip the xml files with some images (pre-existing images hosted on s3)
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自只读文件系统的heroku文档:
您应该能够非常轻松地将生成的 xml 文件写入 tmp/ 并跟踪名称,下载 s3 文件并将其写入同一目录,然后(也许?)调用 zip 命令:只要输出位于
tmp/
中,然后使用正确的 mime 类型将文件提供给浏览器以提示下载。我只关心文件大小有多大,以及heroku 是否对 tmp 目录中允许的内容有未记录的限制。特别是因为您仅在单个请求期间执行此操作以进行一次性下载,所以我认为您很有可能能够做到这一点。编辑:环顾四周,您可能可以使用RubyZip之类的东西来如果您想避免调用系统命令,请创建您的 zip 文件。
From the heroku documentation on the read-only filesystem:
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 intmp/
, 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.