Saving files from post data via sys.stdin
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Saving files from post data via sys.stdin

From: ACB <amy.berry@cox.net>
Date: Tue Apr 11 2006 - 04:21:35 CEST

I am rewriting an existing PERL script I wrote several months ago. It is a
script that is used as the action for a form containing several type="file"
inputs. The script is run unbuffered and writes the data from sys.stdin to
a file which is stat'ed by another script called asyncornously from
javascript. In the end I am able to make a progress bar for file uploads
via http.

Anyway, I have printed sys.stdin to a file and looked at it afterward. This
is what is looks like
-----------------------------126591649570
Content-Disposition: form-data; name="userid"

myUserid
-----------------------------126591649570
Content-Disposition: form-data; name="ulimage"; filename="bc12.jpg"
Content-Type: image/jpeg

binary data of jpeg
-----------------------------126591649570
[plaintext ulimage]
Content-Disposition: form-data; name="ulimage"; filename=""
Content-Type: image/jpeg

-----------------------------126591649570
[plaintext ulimage.1144722095.1647456442]
Content-Disposition: form-data; name="ulimage"; filename=""
Content-Type: image/jpeg

-----------------------------126591649570
Content-Disposition: form-data; name="sessionid"

mySessionid

Normally, I use cgi.FieldStorage() and access the values via calls like
form = cgi.FieldStorage()
sessionid = form["sessionid"].value

What is the best method for accessing the various variables and their
respective values so I can save the files one at a time? Is there some
class that can take this input and make it easier to deal with? I need to
save each of the ulimage values as individual images and gain access to the
values of sessionid and userid.

Thanks
Amy

[plaintext ulimage.1144722095.1169672484]
Received on Sun Apr 30 22:46:05 2006