Multipart-class: Class 'Multipart' and object 'Multipart'

Description Methods See Also Examples

Description

A convenience object for parsing multipart/form-data POST payloads.

Methods

parse(env):

Returns parsed POST payload as a named list. env is an environment created by Rhttpd and conforms to the Rook specification.

See Also

Rhttpd, Request, and Response.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
s <- Rhttpd$new()
## Not run: 
s$start(quiet=TRUE)

## End(Not run)
s$add(name="multi",
    app=function(env){
        req <- Request$new(env)
        res <- Response$new()
        res$write('<form enctype="multipart/form-data" method=POST>')
        res$write('Upload a file: <input type=file name=fileUpload>')
        res$write('<input type=submit></form><br>')
        post <- Multipart$parse(env)
        if (length(post)){
            poststr <- paste(capture.output(str(post),file=NULL),collapse='\n')
            res$write(c('<pre>',poststr,'</pre>'))
        }
        res$finish()
    }
)
## Not run: 
s$browse('multi') # Opens a browser window to the app.

## End(Not run)
s$remove(all=TRUE)
rm(s)

jeffreyhorner/Rook documentation built on May 19, 2019, 4:01 a.m.