Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Uploading files with cgi - binary-files are truncated !?

Reply
Thread Tools

Uploading files with cgi - binary-files are truncated !?

 
 
dermoon
Guest
Posts: n/a
 
      10-08-2003
Made this simple cgi-upload script that uses fieldstorage from a
web-form. ASCII-based files works fine, but if i try to upload
binary-files (word-documents, images) the files seems to be truncated
- e.g. an image-file that contains 3398 bytes is uploaded with only
425 bytes. Am I doing something wrong here?

Here is the code in full:

<!-- The form-->
<FORM METHOD="POST" ACTION="cgi-bin/upload.py"
enctype="multipart/form-data">
<INPUT TYPE=FILE NAME="filename" size=40>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>

#upload.py
print "Content type: text/html"
print
import cgi,sys,traceback,os


def stripPath(fpname):
#strip off leading path and drive stuff from dos/unix/mac files
import string
fname = fpname
for delim in (':','/','\\'):
while (1):
p1 = string.find(fname,delim)
if (p1<0): break
fname = fname[p1+1:]
return(fname)

try:
form=cgi.FieldStorage()
if form.has_key("filename"):
fileitem=form["filename"]

remoteFilename=fileitem.filename

filename = stripPath(remoteFilename)

filedata=fileitem.value
print len(filedata)

localFilename = os.path.join('../', filename)
fstrm = open(localFilename, 'wb')
fstrm.write(filedata)
fstrm.close()

else:
print 'The form is empty!'
except:
sys.stderr = sys.stdout
traceback.print_exc()
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
POST data truncated in a cgi application timnels@gmail.com Perl Misc 3 08-10-2006 05:41 PM
Uploading 2 files with 1 CGI buffer William Perl Misc 10 01-10-2006 07:56 PM
vb.net cgi uploading files marfi95@yahoo.com Perl Misc 4 11-08-2005 09:42 PM
maybe OT: uploading files w/ cgi darius Perl Misc 2 07-21-2004 06:30 PM
Uploading files using CGI.pm D Borland Perl Misc 4 09-29-2003 10:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57