473,396 Members | 2,037 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,396 software developers and data experts.

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

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()
Jul 18 '05 #1
0 1606

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

Similar topics

7
by: lion | last post by:
I get these errors when uploading images via a web page: (the page still uploads the images but reports these errors?) Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) : failed to create stream: No...
2
by: JonChart | last post by:
Hi all, I would like to know ho to validate a file name when uploading via asp. I need to upload 2 images and the file names must be the same... 1) browse for 1st image. 2) image path and...
1
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for...
11
by: bissatch | last post by:
Hi, I am trying to upload an image, create a new file based on that image and then store the base64 encoded image data in a database. I dont really know where my code is going wrong so I will...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
3
by: Jason Chu | last post by:
I've written a file uploading part of my application using the IHttpModule. So now, I don't have the memory problem of uploading something big. Problem: I can't find which function I have to...
3
by: Carlos | last post by:
Hello Forum, I would appreciate it if you could recommend settings to use auto-vacuum in my version 7.4 database. I am uploading several thousands records in the database at a rate of ~1 second...
3
by: Charlie | last post by:
Hi: I'm working on an application that uploads images into binary fields on SQL Server. Before submitting, I would like to validate size of image (ie, 75 pixels by 75 pixels) so that images are...
4
by: | last post by:
Can someone offer or point me to some sample code or advice on how to upload a document from a web page and store it into a SQL Server image field? And then reverse the process and serve up the file...
3
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.