473,729 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FieldStorag e() and access the values via calls like
form = cgi.FieldStorag e()
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 1987
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.FieldStorag e() and access the values via calls like
form = cgi.FieldStorag e()
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.FieldStorag e()

for k in form.keys():
do_something_wi th(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_some thing()

form = cgi.FieldStorag e()

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

for k in form.keys():
do_something_wi th(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.FieldStorag e()

for k in form.keys():
do_something_wi th(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@fed1rea d07...
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.FieldStorag e() and access the values via calls like
form = cgi.FieldStorag e()
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1680
by: edJames | last post by:
Hi Im writing a java applet that calls a perl script to save pictures generated by the applet locally. The applet converts the onscreen buffer into a GIF and sends in via POST in a byte stream. The problem im having is at the cgi end. The data should be saved as a .gif file, but when I do this nothing gets saved. If I save it as a text file I get a load of unrecognisable characters. Below is my perl code, ive tried adding binmode and it...
12
2886
by: expect | last post by:
What's the big deal with importing text files? I have a 70 MB file to import and it's been one problem after another. I used the copy command and it appears that it's just not possible. I finally massaged the file into a .sql file and ran that using \i db.sql but that failed too because I overlooked ' in names like D'Adario. The other problem I encountered was that a numeric field had to have data in it, pg would not default to the...
11
4760
by: MM | last post by:
Hi I have never written any C programs before, but it seems that I need to do so now. Hope some of you out there can spend a few minutes and help me by writing a simple example of something fairly similar to what I need. I really think it is a simple matter if you know C programming, but to me it is not easy at all. An example from some "professional" C programmer will probably give me all I need to complete it into exactly what I need....
3
2298
by: kimimaro | last post by:
hi below is my save function that is used to placed data from the C program to a text file for future usage. void save() { FILE *save; int i = 0; save=fopen("employeerecord.txt", "a+");
6
2232
by: Ramesh | last post by:
Hi, We are receiving an error 'The operation has timed out' when our ASP.NET application on Web Server stores large files 10MB+ on the App Server using HTTP PUT. This is a Server to Server communication. This works fine with 4-5 MB files though. Also there is a 15 mb shared bandwidth limitation. how can we throttle/control the transfer rate to see that we are within the bandwidth limits ? Any help is highly appreciated
2
1552
by: Madhusudhanan Chandrasekaran | last post by:
Hi: This question is not directed "entirely" at python only. But since I want to know how to do it in python, I am posting here. I am constructing a huge matrix (m x n), whose columns n are stored in smaller files. Once I read m such files, my matrix is complete. I want to pass this matrix as an input to another script of mine (I just have the binary.) Currently, the script reads a file (which is nothing but the
4
6723
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my code ?? thank you Pedro Leite From Portugal ------------------------------------
0
1998
by: Oliver Bleckmann | last post by:
hey guys, i have a little problem. my cgi routines are working so far, but i need to redirect to the cgi-programm and what the "posted" data to be cleared if redirected. i don't know how the post method exactly works. maybe i have to clear the stdin (tried fflush)!? maybe the is another reason that the former data is displayed. fist i thought of the browser cach, but it's the same problem using ctrl+f5. i need to check if the cgi program...
1
1838
by: fatjoez | last post by:
Hey there. I've been trying to modify my file upload script so that it handles 10 files instead of one. i was thinking the most straightforward way would be to add a FOR LOOP? placed strategically somewhere like just before the my variables get declared??? the POST input name is "fileup" so maybe i could call them fileup1, fileup2 etc. This is the upld.pl script itself.
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.