Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Perl parsing of multipart content

by daxim (Curate)
on Jun 14, 2019 at 07:32 UTC ( [id://11101330]=note: print w/replies, xml ) Need Help??


in reply to Perl parsing of multipart content

See Plack::Request methods "parameters" and "uploads". This should be very familiar to you if you know CGI.pm.

Server (this is one line):

plackup -MPlack::Request -MDDP -e'my $app = sub { my ($env) = @_; my $ +req = Plack::Request->new($env); p $req->parameters; p $req->uploads; + return [200,[],[]]; };'

Client:

curl -v -F somekey=somevalue -F upload=@somefile http://localhost:5000

HTTP trace:

POST / HTTP/1.1 Host: localhost:5000 User-Agent: curl/7.65.0 Accept: */* Content-Length: 322 Content-Type: multipart/form-data; boundary=------------------------84 +f03d39abacb4c6 --------------------------84f03d39abacb4c6 Content-Disposition: form-data; name="somekey" somevalue --------------------------84f03d39abacb4c6 Content-Disposition: form-data; name="upload"; filename="somefile" Content-Type: application/octet-stream somefilecontent --------------------------84f03d39abacb4c6-- HTTP/1.0 200 OK Date: Fri, 14 Jun 2019 07:22:11 GMT Server: HTTP::Server::PSGI Content-Length: 0

Abbreviated server output:

Hash::MultiValue { public methods (24) : … private methods (2) : … internals: { somekey "somevalue" } } Hash::MultiValue { public methods (24) : … private methods (2) : … internals: { upload Plack::Request::Upload } } 127.0.0.1 - - [14/Jun/2019:09:22:11 +0200] "POST / HTTP/1.1" 200 0 "-" + "curl/7.65.0"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11101330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found