Professional Web Applications Themes

LWP - multipart/form-data file upload from scalar rather than local file - PERL Modules

I'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'), ...

  1. #1

    Default LWP - multipart/form-data file upload from scalar rather than local file

    I'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.

    Swervo Guest

  2. #2

    Default Re: LWP - multipart/form-data file upload from scalar rather than local file

    On Wed, 28 Sep 2005 12:33:15 -0700, Swervo wrote:
    > I'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.
    I know it's bad form to respond to oneself, but figured I'd mention that
    it appears the only way to accomplish this is modify
    HTTP::Request::Common, or in my case, create my own module with most of
    the same code, but accept a filehandle as the first argument rather than
    the name of a local file. Works like a charm.

    -- Swervo

    Remove S, P, A, and M from address to email me.

    Swervo Guest

  3. #3

    Default Re: LWP - multipart/form-data file upload from scalar rather than local file

    So you know, I was having the same problem myself, and found a way to
    do this without rewriting the HTTP::Request::Common module ->

    my $ua = new LWP::UserAgent;
    $response=$ua->request(POST $URL,
    Content_Type => 'multipart/form-data',
    Content => [ $PARAM => [undef,$FILENAME, Content => $CONTENTS ] ]);

    Where $PARAM is the name of the parameter, $FILENAME is what you want
    to call the file, and $CONTENTS is a scalar holding the contents of the
    file.

    Scott
    Swervo wrote:
    > On Wed, 28 Sep 2005 12:33:15 -0700, Swervo wrote:
    >
    > > I'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.
    >
    > I know it's bad form to respond to oneself, but figured I'd mention that
    > it appears the only way to accomplish this is modify
    > HTTP::Request::Common, or in my case, create my own module with most of
    > the same code, but accept a filehandle as the first argument rather than
    > the name of a local file. Works like a charm.
    >
    > -- Swervo
    >
    > Remove S, P, A, and M from address to email me.
    scottbjer@gmail.com Guest

Similar Threads

  1. file upload, multipart form, and cgi::cache
    By LLcoolSay in forum PERL Modules
    Replies: 0
    Last Post: April 21st, 11:01 AM
  2. file upload form enctype="multipart/form-data
    By kbuska525 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: June 27th, 04:52 AM
  3. #25995 [Asn]: multipart/form-date file upload problem.
    By s dot masugata at digicom dot dnp dot co dot jp in forum PHP Development
    Replies: 0
    Last Post: October 30th, 04:27 AM
  4. #25995 [Opn->Asn]: multipart/form-date file upload problem.
    By moriyoshi@php.net in forum PHP Development
    Replies: 0
    Last Post: October 28th, 02:27 PM
  5. #25995 [NEW]: multipart/form-date file upload problem.
    By s dot masugata at digicom dot dnp dot co dot jp in forum PHP Development
    Replies: 0
    Last Post: October 26th, 11:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139