6

The HTML5 specification allows multiple files to be uploaded at once via <input type="file", ..., multiple="multiple">. Is there a way to take advantage of this with the Rook R package?

Here's my attempt, but it seems to only show one of the selected files:

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)
rcs
  • 67,191
  • 22
  • 172
  • 153
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • Hmmm... you may want to send this to Rook mailing list. I know that it's possible to upload multiple files with RApache. – aL3xa Jun 26 '11 at 17:22

1 Answers1

4

The spec isn't supported fully yet; I just tried on Chrome 12.0.742.100 and the browser interface doesn't even allow one to choose multiple files.

To upload multiple files you will want to create multiple input elements like so:

<input type="file" name="file1">...
<input type="file" name="file2">...
...
Jeff
  • 1,426
  • 8
  • 19
  • Thanks for the answer. I was able to *select* multiple files with Firefox 4.x, but I didn't see them in the Rook environment. – Joshua Ulrich Jun 27 '11 at 15:39