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)
答案 0 :(得分:4)
尚未完全支持该规范;我刚试过Chrome 12.0.742.100,浏览器界面甚至不允许选择多个文件。
要上传多个文件,您需要创建多个输入元素,如下所示:
<input type="file" name="file1">...
<input type="file" name="file2">...
...