473,498 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CGI File Uploads and Progress Bars

Hey, Folks:

I'm writing a CGI to handle very large file uploads. I would like to
include a progress bar. I think I'm about done. I have code to handle the
file upload, and I think I can add an IFrame to my page which posts to check
file size (so I can tell how many bytes have been received). My problem is
that I want to provide a % complete. In order to do that, of course, I need
to know not only the number of bytes received, but also the total number of
incoming bytes. Here's the heart of the code:

while afcommon.True:
lstrData = lobjIncomingFile.file.read(afcommon.OneMeg)
if not lstrData:
break
lobjFile.write(lstrData)
llngBytes += long(len(lstrData))
lobjFile.close()

Assume that lobjIncomingFile is actually a file-type element coming from
CGI.FieldStorage. It's already been tested to ensure that it is a file-type
element. Also, assume that I've already opened a file on the server,
referred to by lobjFile (so lobjFile is the target of the incoming data).

If this were a client application opening a file, I would just do the
following:

import os
print os.stat('myfile.dat')[6]

But, of course, this isn't a local file. In fact, it's not really a file at
all. It is the contents of a file already rolled up into the HTTP header of
the incoming HTTP request to the Web server. The CGI module is kind enough
to handle all of the really hard stuff for me (like unpacking and decoding
the header contents, etc.). But, I still need to know the size of the
incoming file data.

Of course, I could do this by reading the whole thing into a string variable
and then testing the length of the string, as follows:

s = lobjIncomingFile.file.read()
SizeOfFileIs = len(s)

But that really defeats the purpose, since my whole goal here is to provide
a progress bar, which is contingent upon a "chunking" approach. Besides,
for the file sizes that I'll be dealing with, I surely wouldn't want to read
the whole thing into memory.

So, bottom line: Does anyone know how to get the size of the incoming file
data without reading the whole thing into a string? Can I do something with
content_header?

Thanks much for any insight that you might have.

Doug
Sep 8 '05 #1
1 3515
> So, bottom line: Does anyone know how to get the size of the incoming file
data without reading the whole thing into a string? Can I do something with
content_header?


http://www.faqs.org/rfcs/rfc1867.html

It seems that _maybe_ you can use the content-length http header. But it
looks as if it's not mandatory in this case - and of course uploading
multiple files will only allow for an overall percentage.
Diez
Sep 8 '05 #2

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

Similar topics

7
2412
by: OneSolution | last post by:
Hi All, Here's one thing that I don't know much about - file uploading. As part of my project, I will have to build a file manager of sorts - perhaps a document manager. Anyhow, this involves...
14
1949
by: Todd Denlinger | last post by:
Ok, I know how to upload a file in asp.net using the <input type="file" runat="server"> control. What I don't know how to do is monitor the progress of the upload so that I can show the...
5
2414
by: Keith Rebello | last post by:
I have a couple of progress bars that indicate the progress of a math-intensive application. They are working well. The only problem is that the progress indicator is gray in color. Is it...
12
7737
by: JMB | last post by:
Hello, I was wondering if anyone knew of any projects extending the inline upload progress bar to utilize an inpage image uploader with bar, without having to refresh or go to a seperate page,...
6
10082
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
5
2281
by: LtCommander | last post by:
Hello all, 1. I am a little new to ASP.NET, so please bear with me. 2. I am trying to create a very simple website which requires an upload box (end user file sizes may be anywhere between 1MB...
3
19826
by: markus.rietzler | last post by:
i want to do (multiple) file upload(s) and display a progress bar. with firefox and safari it is no problem at all. only IE makes some problems. my script is based on ajax-uploader, which can be...
5
4707
by: John Devlon | last post by:
Hi, Some people like to go on vacation during christmas time, others try to do something they never did before.... I would like to create a multiple file upload page, with some nice progress...
3
1289
by: darrel | last post by:
I briefly researched this a year or so ago for a project that never materialized, but now I'm in the midst of one and need to look into this a bit more. I'm working on a site where the client...
0
7121
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
6993
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...
0
7162
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,...
1
6881
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
7375
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...
1
4899
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...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
287
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...

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.