Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperating variables and files in multipart/form-data #11

Open
jeroen opened this issue Mar 12, 2013 · 0 comments
Open

Seperating variables and files in multipart/form-data #11

jeroen opened this issue Mar 12, 2013 · 0 comments

Comments

@jeroen
Copy link
Collaborator

jeroen commented Mar 12, 2013

In RApache, request data for a multipart/form-data HTTP POST will be
available in the session in two files:

POST : contains posted form variables
FILES: contains posted files

I am trying to accomplish the same in Rook. However, both the output
of req$POST() and Multipart$parse(env) contain a mix of the files and
arguments.

Questions:

  • Is there a native way to get just the FILES, and just the arguments
    from a http post request, as in rapache? Or do I need to extract these
    from the POST() output?
  • Are Multipart$parse(env) and req$POST supposed to return the same output?

Below a modified example from the manual

library(Rook)
s <- Rhttpd$new()
s$start(quiet=TRUE)

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> <br />')
            res$write('Some variables: <input type="text" name="somevar">  <br />')
            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>'))
            }

            HTTPPOST <- req$POST();
            if (length(HTTPPOST)){
                    newstr <- paste(capture.output(str(HTTPPOST),file=NULL),collapse='\n')
                    res$write(c('<pre>',newstr,'</pre>'))
            }


            res$finish()
    }
)

s$browse('multi')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant