Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How can I upload a file using HTTP POST with Content-Type=multipart/form-data?

by bhess (Initiate)
on Sep 19, 2000 at 06:27 UTC ( [id://33048]=note: print w/replies, xml ) Need Help??


in reply to How can I upload a file using HTTP POST with Content-Type=multipart/form-data?

Thanks for the feedback... I am looking for the client side HTTP::Request::Common works OK for small files, but I need a solution that can handle very large files (100 MB+). I can upload very large files using a web browser (Netscape and IE). LWP seems to "slurp" the file before writing it to the Content-Disposition section of the HTTP message, thus causing memory woes on the client - this is also very slow. I am looking for some client side Perl that opens a socket and generates the appropriate HTTP to upload any file - no matter the size - here is an example of a very small text file:
POST /cgi-bin/upload.pl HTTP/1.1 Accept: application/vnd.ms-excel, application/msword, application/vnd. +ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, a +pplication/pdf, */* Referer: http://deville/cgi-bin/upload.pl Accept-Language: en-us Content-Type: multipart/form-data; boundary=-------------------------- +-7d03135102b8 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT) Host: deville Content-Length: 316 Connection: Keep-Alive -----------------------------7d03135102b8 Content-Disposition: form-data; name="file"; filename="D:\hess\dev\www +\notes\hello.txt" Content-Type: text/plain Hello there -----------------------------7d03135102b8 Content-Disposition: form-data; name="done" done -----------------------------7d03135102b8--
This is an actual header that I sniffed coming from IE 5 on Win NT. I cannot seem to reproduce this header - even hardcoded - to upload t
  • Comment on Re: How can I upload a file using HTTP POST with Content-Type=multipart/form-data?
  • Download Code

Replies are listed 'Best First'.
RE: Answer: How can I upload a file using HTTP POST with Content-Type=multipart/form-data?
by merlyn (Sage) on Sep 19, 2000 at 08:22 UTC
    Read further down in the LWP::Request::Common:
    If you set the $DYNAMIC_FILE_UPLOAD variable (exportable) to some TRUE value, then you get back a request object with a subroutine closure as the con- tent attribute. This subroutine will read the content of any files on demand and return it in suitable chunks. This allow you to upload arbitrary big files without using lots of memory. You can even upload infinite files like /dev/audio if you wish. Another difference is that there will be no Content-Length header defined for the request if you use this fea- ture. Not all servers (or server applications) like this.
    Still no reason to write the code yourself. Remember... LWP has had many many man-years of coding put into it. Don't reinvent the wheel.

    -- Randal L. Schwartz, Perl hacker

      I have tried using this with no luck in the past and gave up. I wrote a simple client script using HTTP::Request::Common and had it working with small files and then set the DYNAMIC_FILE_UPLOAD variable at the beginning of the script. And this seemed to break it. Is there something else I need to do? Also, I am using Apache as my server. Is there some setting in Apache that I will need because of no Content-Length? Thanks
        Show your 'simple script' and we might find out what went wrong...

        Jouke Visser, Perl 'Adept'
        Hi, I am looking for this exact solution... Do you have an example I could possibly use? Thanks in advance a.fitzpatrick@exec.com.au

Log In?
Username:
Password:

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

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

    No recent polls found