Hi,
I have a simple CGI program that allows that user to upload a file.
However, since accessing the the value of the uploaded file using the
value attribute or the getvalue() method reads the entire file in memory
as a string which is not what I want I'm making use of the file module.
The problem is that all the my checks including "assert fileStream.file
in not None" return true however readline() does not return the next
line of the fileStream.file object! What am I doing wrong? Here's my code:
Here's my code:
caller:
dataFile = form['data_file']
fileproc = redrev.FileStreamProcessor()
dataLines = fileproc.readStream(dataFile)
callee:
def readStream(self, fileStream):
'''readStream: reads a stream of input returns a list of lines'''
# list to hold data lines
fileLines = []
# make sure that the stream has been provided
try:
assert fileStream.file is not None
except Exception, e:
"No input to process"
# use filestream object to get uploaded file's lines one by one
if fileStream.file:
while 1:
line = fileStream.file.readline()
if not line:
break
# process and store the line
line.strip()
fileLines.append(line)
return fileLines
Thanks,
Kiana