469,323 Members | 1,596 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Saving files from post data via sys.stdin

ACB
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
Content-Disposition: form-data; name="ulimage"; filename=""
Content-Type: image/jpeg

-----------------------------126591649570
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
Apr 11 '06 #1
4 1859
ACB wrote:
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
Content-Disposition: form-data; name="ulimage"; filename=""
Content-Type: image/jpeg

-----------------------------126591649570
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?
Maybe loop over form's keys...

form = cgi.FieldStorage()

for k in form.keys():
do_something_with(form, k)
Is there some
class that can take this input and make it easier to deal with?
A dictionary.

I need to save each of the ulimage values as individual images and gain access to the
values of sessionid and userid.

Thanks
Amy


images = get_images_from_pickle_or_something()

form = cgi.FieldStorage()

if not images.has_key(form['ulimage']):
an_image = image_constructor(form['ulimage'])
images[form['ulimage']] = an_image
else:
an_image = images[form['ulimage']]

for k in form.keys():
do_something_with(an_image, form[k])
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Apr 11 '06 #2
ACB
form = cgi.FieldStorage()

for k in form.keys():
do_something_with(form, k)
Is there some class that can take this input and make it easier to deal
with?


A dictionary.

I need to
save each of the ulimage values as individual images and gain access to
the values of sessionid and userid.

James,

Thanks for the reply, however... the problem I am having is that I need to
use the data via sys.stdin and not the cgi.FormStorage object because cgi
only takes the data after it has all been received.

So, I need a good way to parse the data in sys.stdin unless their is some
built-in way to do it.

Thanks
Apr 11 '06 #3
ACB

"ACB" <am*******@cox.net> wrote in message
news:KoE_f.200$Oe2.100@fed1read07...
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
Content-Disposition: form-data; name="ulimage"; filename=""
Content-Type: image/jpeg

-----------------------------126591649570
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


Any further help is appreciated. : )
Apr 11 '06 #4
ACB
Any further help is appreciated. : )


I figured it out. I just used
sys.stdin = file("path/to/file", "r")
and I was again able to read the data from stdin.

Apr 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by edJames | last post: by
12 posts views Thread by expect | last post: by
11 posts views Thread by MM | last post: by
3 posts views Thread by kimimaro | last post: by
6 posts views Thread by Ramesh | last post: by
2 posts views Thread by Madhusudhanan Chandrasekaran | last post: by
reply views Thread by Oliver Bleckmann | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.