473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

http file post

Greetings.

Ive been trying to figure out how I can write to a file from an HTTP
post while it is being uploaded. So far ive realized that my script
isn't getting the data until the browser is done uploading. What I want
to accomplish is a way to track the progress of a file upload. I'm
guessing that if I can get it to write to a file as it is uploaded I can
load another browser to check the progress of the transfer (by refreshing).

Here is the general idea I have tried:

if item.file:
filen = item.filename
filen1 = filen.split('\\')
filen2 = filen1[len(filen1)-1]
outfile = open(path + filen2 + '.tmp','wb')
buff = item.file.read(40000)
while buff != "":
outfile.write(buff)
buff = item.file.read(40000)
if not buff:
break

Works, but I recieve the data all at once rather then while..

Perhaps it is my ignorance about how http works and that there is no
other way?

Thanks in advance.
-Dave

Jul 18 '05 #1
2 2501
Dave <xg***@k-theory.com> wrote:

Ive been trying to figure out how I can write to a file from an HTTP
post while it is being uploaded. So far ive realized that my script
isn't getting the data until the browser is done uploading. What I want
to accomplish is a way to track the progress of a file upload.


This IS possible, but you'll have to do some work.

I assume this is a CGI script, and that you're using cgi.FieldStorage() to
fetch the POST contents. The key problem for you is that
cgi.FieldStorage() (and, more specifically, cgi.FieldStorage.read_binary)
does not return until the entire transmission is complete.

Now that you know that, your path should be clear: all you need to do is
make your own custom version of FieldStorage that updates a status variable
somewhere. Piece of cake!
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2
Kind of rough but I figured it out. If anyone finds this usefull:

HTTP File upload handler with progress indicator
http://projects.battlestyle.org/

-dave

----- Original Message -----
From: "Tim Roberts" <ti**@probo.com>
Newsgroups: comp.lang.python
To: <py*********@python.org>
Sent: Monday, May 31, 2004 5:37 PM
Subject: Re: http file post

Dave <xg***@k-theory.com> wrote:

Ive been trying to figure out how I can write to a file from an HTTP
post while it is being uploaded. So far ive realized that my script
isn't getting the data until the browser is done uploading. What I want
to accomplish is a way to track the progress of a file upload.
This IS possible, but you'll have to do some work.

I assume this is a CGI script, and that you're using cgi.FieldStorage() to
fetch the POST contents. The key problem for you is that
cgi.FieldStorage() (and, more specifically, cgi.FieldStorage.read_binary)
does not return until the entire transmission is complete.

Now that you know that, your path should be clear: all you need to do is
make your own custom version of FieldStorage that updates a status

variable somewhere. Piece of cake!
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sugapablo | last post by:
How do I display all of the POST headers? What I want to see is all information related to a POSTed file and it's attributes, sort of like this: POST /file.php?var=value HTTP/1.0 Host:...
1
by: Dan Corkum | last post by:
Good morning. I am working on an issue that is just baffling me. I have developed an .aspx page that receives an http form post that has a "file" attribute. When I do testing with a test post...
0
by: Dan Corkum | last post by:
Good morning. I am working on an issue that is just baffling me. I have developed an .aspx page that receives an http form post that has a "file" attribute. When I do testing with a test post...
1
by: Jason Ho | last post by:
Hi, I would like to send a jpg file to a HTTP server by POST request. But I am not using a browser to do this, I use a Windows Form instead. I know how to send typical request by POST with code...
3
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to...
6
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out...
2
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata ...
0
by: phpfreak2007 | last post by:
Hi all, I am trying to upload file using VB HTTP Post method and winsock control . Can successfully upload the files when client machine is English OS, but create problem when upload from Chinese...
5
by: manheim | last post by:
I have a page posting a raw jpg to me via HTTP POST. All reference I've found is centered around retrieving POST data as name/value pairs which will not work in this situation. What I need to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.