r1n0 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have an IO::Socket server that I created for a Proxy server. It works fine, but I want to add the ability to allow users to upload files to the server. The user will be allowed to define the URI that holds the file, too. I want to provide the user with the ability to upload files to the server via their browser. My question is this:

Does a perl module exist that will help breakdown the browser sent header information so I can easily identify the actual file content before saving it off? I will be feeding it raw IO::Socket content, if possible.

I currently have the upload HTML file using the POST method for sending the file. I plan on posting some code, but can't today since I am away from my development machine and don't have access to what I have, now. It is a must that I stay with IO::Socket at the moment, since I already have that coded into the server I have created. Changing it would require a lot of rewrite.

Thank you in advance for your help.
  • Comment on Upload File to IO::Socket server via browser

Replies are listed 'Best First'.
Re: Upload File to IO::Socket server via browser
by Corion (Patriarch) on Nov 13, 2009 at 15:39 UTC

    I'm not sure, but from your description, it sounds as if CGI.pm fits the bill.

    If you want to be able to let your users instruct your program to fetch a URL, I guess that LWPx::ParanoidAgent is the thing to use, as it's paranoid not to trust the content and connection to be well-behaved.

      CGI.pm is great for Apache CGI scripts, but not sure if that will work with an IO::Socket server

      Also, I am not instructing the server to go fetch a URL. Rather, what I am doing is allowing the user to upload a file to the server and provide the URL they want it stored under. Then, if any other user requests the URL from the proxy, the proxy will server the file the original user uploaded. This will give users the ability to upload files to the proxy server such as:
      Their resume and store it under http://resumebank.company/joe_smith.doc

      or something like that. This is a test thing rather than a production piece. Well aware users might put the wrong extension on things. Once this is all figured out, I will write a piece to make sure they get the extension right.

      Thanks.

        It sounds to me as if you're not implementing a "proxy server" but simply a small HTTP server. Then, on the receiving side, CGI.pm would be what you want, potentially coupled with HTTP::Server::Simple, or, as a more advanced solution, any of the other HTTP server implementations in Perl.

Re: Upload File to IO::Socket server via browser
by rowdog (Curate) on Nov 14, 2009 at 12:17 UTC

    As Corion++ has pointed out, you can use CGI. I suppose the primary alternative is to impliment RFC 1867 yourself.

      Thank you one and all for the feedback you have provided. I ended up adding an RFC 1867 decoder-like capability to my proxy system prior to reading rowdog's feedback. It made me happy to see someone recommended to try that, too. I focused on collecting all of the input from the user's browser (file + header + content information) and broke it down from there. A very important part is the "boundary=" information provided from the browser. Once you identify this information (and have collected it all), you can break it down by using the "boundary" value as the separator.

      Thanks again.