如何在 Ruby 中访问上传的文件
我正在尝试在 ROR 应用程序中使用 Java 上传器(以便轻松上传整个目录)。所选上传器附带一些 PHP 代码,用于将文件保存到服务器。我正在尝试将此代码翻译为 Ruby,但在这一点上感到困惑:
PHP 有一个非常方便的超全局变量 – $_FILES – 它包含通过 HTTP POST 方法上传到当前脚本的所有文件的哈希值。 Ruby 似乎没有类似的资源。如果缺少这一点,访问和保存上传文件的最佳方法是什么?
我正在使用 JavaPowUpload 上传器 ( http://www.element-it.com/OnlineHelpJavaPowUpload /index.html )。
I am trying use a Java Uploader in a ROR app (for its ease of uploading entire directories). The selected uploader comes with some PHP code that saves the files to the server. I am trying to translate this code to Ruby, but am stumped on this point:
PHP has a very convenient superglobal – $_FILES – that contains a hash of all files uploaded to the current script via the HTTP POST method. It appears Ruby does not have a similar resource. Lacking that, what is the best way to access and save the uploaded files?
I am using the JavaPowUpload uploader ( http://www.element-it.com/OnlineHelpJavaPowUpload/index.html ).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ruby on Rails 允许您使用应用程序根目录通过 #{RAILS_ROOT} 获取存储的文件(无论您决定将其放在哪里)。
查看此教程。这不是最漂亮的方法,但它应该让您了解需要做什么。文件上传后,只需获取正确的路径并从那里进行处理即可。
ruby on rails allows you use the application root directory to get at the file stored (wherever you have decided to put it) via #{RAILS_ROOT}.
Check out this tutorial. Not the prettiest method, but it should give you an idea of what needs to be done. Once the file is uploaded, it's just a matter of getting the right path and doing your processing from there.