【问题标题】:Upload multiple files with Rook使用 Rook 上传多个文件
【发布时间】:2011-09-23 01:05:53
【问题描述】:

HTML5 规范允许通过<input type="file", ..., multiple="multiple"> 一次上传多个文件。有没有办法通过Rook R 包利用这一点?

这是我的尝试,但它似乎只显示选定的文件之一:

library(Rook)

app <- function(env) {
  req <- Rook::Request$new(env)
  res <- Rook::Response$new()
  res$write(
   '<html><body>
      Select files:
      <form method="POST" enctype="multipart/form-data">
        <input type="file" name="data" multiple="multiple">
        <input type="submit" name="Upload">
      </form>
    </body></html>')

  if (!is.null(req$POST())){
    data <- req$POST()[['data']]
    res$write("<pre>")
    res$write(paste(capture.output(req$POST(),file=NULL),collapse='\n'))
    res$write("</pre>")
    res$write("<pre>")
    res$write(paste(capture.output(data$filename,file=NULL),collapse='\n'))
    res$write("</pre>")
  }
  res$finish()
}

s <- Rhttpd$new()
s$add(app=RhttpdApp$new(name="app", app=app))
s$start(listen="127.0.0.1", quiet=FALSE)
s$browse(1)

#s$stop(); s$remove(all=TRUE); rm(s)

【问题讨论】:

  • 嗯...您可能希望将其发送到 Rook 邮件列表。我知道使用 RApache 可以上传多个文件。

标签: html r r-rook-package


【解决方案1】:

尚不完全支持该规范;我刚刚在 Chrome 12.0.742.100 上尝试过,浏览器界面甚至不允许选择多个文件。

要上传多个文件,您需要创建多个输入元素,如下所示:

<input type="file" name="file1">...
<input type="file" name="file2">...
...

【讨论】:

  • 感谢您的回答。在 Firefox 4.x 中,我能够选择多个文件,但在 Rook 环境中没有看到它们。
猜你喜欢
  • 2022-08-02
  • 1970-01-01
  • 2014-05-04
  • 2013-05-04
  • 2016-08-10
  • 1970-01-01
  • 1970-01-01
  • 2017-01-13
  • 2012-10-10
相关资源
最近更新 更多