LWP - multipart/form-data file upload from scalar rather than local file
am 28.09.2005 21:33:15 von SwervoI'm looking to do an HTTP upload, preferably with HTTP::Request::Common,
but get the file data from either a filehandle or a scalar rather than
give it a local filename.
For some background, I'm making a psuedo-proxy for an HTTP file upload.
The user uploads an image from their browser to a mod_perl server. The
server then changes around some of the arguments, namely taking a session
ID out of the post data and adding it to the query string, then sends that
modified request off to the final destination server.
I can get to the Apache upload object via $r->upload('Image'), then get a
filehandle from $upload->fh(); At that point, I want to either pass that
filehandle or read from that filehandle into a scalar, then pass that to
LWP for an upload.
There's a bit in the perldoc for HTTP::Request::Common, in the POST
section, that says "The first value in the array ($file) is the name of a
file to open. This file will be read and its content placed in the
request. The routine will croak if the file can't be opened. Use an
'undef' as $file value if you want to specify the content directly."
However, that's the last mention at all of using undef for $file, I can't
seem to find any more information on this. According to the doc, the
array should be [ $file, $filename, Header => Value... ]. Assuming that
the file contents would be somewhere in that Header => Value section, I
have no idea what Header to give it.
Is there a way to pass a scalar or a filehandle to LWP for an upload, or
do I have to give it a local filename to read from? I'd prefer not to
write temporary files for this if I can help it, but I can do that if
there's no other way around this.
Also, let me know if I'm barking up the wrong tree with the way to
accomplish this goal. All I'm really trying to do is take one of the
name/value pairs out of the POST content and attach it to the URL as part
of a query string, so it's entirely possible there's a far better way to
do this.
Thanks!
-- Swervo
Remove S, P, A, and M from address to email me.