使用 rubyzip 打开 multipart/form-data ZIP 文件
我想提取上传到 Rails 应用程序的 ZIP 文件中的文件。 ZIP 文件中的文件将存储在数据库中。
我想在我的操作中打开 ZIP 文件,而不必先将文件保存到文件夹中 - 我想使用 rubyzip 打开 multipart/form-data 流。
看起来 rubyzip 的 ZipFile.open 只接受文件名 - 而不是 IO 流。
我需要在 rubyzip 中更改什么,才能允许我以流的形式打开 zip 文件,如下所示:
Zip::ZipFile.open(params["zip_file"]) do |zip_file|
...
end
谢谢。 约尔格
I want to extract the files within a ZIP file I uploaded to my Rails app. The files within the ZIP file are going to be stored in the database.
I want to open the ZIP file in my action, without first having to save the file to a folder - I want to open the multipart/form-data stream with rubyzip.
It looks like rubyzip's ZipFile.open only takes a filename - not an IO stream.
What do I need to change within rubyzip, to allow me to open the zip file as a stream, like this:
Zip::ZipFile.open(params["zip_file"]) do |zip_file|
...
end
Thanks.
Joerg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
应该有效。
Using
should work.
我将给你一些你没有要求过的建议。
我强烈建议您不要在操作中执行此操作,因为只要执行提取所需的时间,它就会阻塞与该 HTTP 请求关联的 Rails 进程。 该用户的 UI 将变得无响应,如果有足够多的用户同时执行此操作(您正在限制文件上传大小,对吗?),那么您实际上就得到了 针对您的应用程序的拒绝服务攻击。
I'm going to give you some advice that you haven't asked for.
I would strongly advise that you don't perform this operation from within your action, because it will block the Rails process associated with that HTTP request for as long as it takes to perform the extraction. Your UI for that user will become unresponsive and if enough users do this simultaneously (you are limiting the file upload size, right?) then you've effectively got a Denial of Service attack going on against your application.