durusmail: quixote-users: upload binary file
upload binary file
2006-03-07
Tom Lesters
2006-03-08
Mike Orr
upload binary file/current state of quixote
2006-03-08
Bo Yang
Re: upload binary file/current state of quixote
2006-03-08
mario ruggier
2006-03-08
David Binger
2006-03-09
Bo Yang
2006-03-08
Mike Orr
Quixote, QP, the future...?
2006-03-08
Titus Brown
2006-03-09
David Binger
2006-03-09
Graham Fawcett
2006-03-09
Graham Fawcett
2006-03-09
David Binger
2006-03-09
Mike Orr
2006-03-09
David Binger
2006-03-09
Bo Yang
2006-03-09
Bo Yang
upload binary file
Mike Orr
On 3/7/06, Tom Lesters  wrote:
>
> Hi All,
>
> Seems upload binary files should be really easy in Quixote,
> There are Upload class,
> But I could not find how to receive, save file in the demo
> Look at the source code, seem it's more about txt file.
> the example on quixote cookbook is out dated: there is no tmp_filename
> anymore:
>
> http://www.quixote..ca/qx/UploadingFiles
> def count (request):
>   upload = request.get_field('file')
>     lines = 0
>     for line in open(upload.tmp_filename, 'r'):
>         lines += 1
>     return "

The file is %i lines long." % lines > > Anybody can point to me 3-5 line code of checking the binary file size then > save it ? To get the file size from a file widget value ('upload' variable): pos = upload.fp.tell() # Save current position in file. upload.fp.seek(0, 2) # Go to end of file. size = upload.fp.tell() # Get new position (which is the file size). upload.fp.seek(pos, 0) # Return to previous position. upload.size = size if size > max_size: msg = "The uploaded file is too big (size=%s, max=%s bytes)" msg %= (size, max_size) raise QueryError(msg) I've proposed having the Quixote set the size as 'upload.size' for this purpose, but it hasn't been implemented. Then to save the upload in a file: f = open(DEST_FILENAME, 'wb') # Copy file in chunks to avoid using lots of memory. while 1: chunk = upload.read(1024 * 1024) if not chunk: break out.write(chunk) out.close() upload.close() -- Mike Orr (mso@oz.net address is semi-reliable)

reply