Here's an idea for you. I use some of the code below in my FileBase product to receive uploads, although, I've added some "code" I think might help you for grabbing just the header. Although I'm not sure if the file descriptor that infile claims from the form has already been loaded into either a StringIO or some other "buffer" (i.e. already received in full from client), it's possible that this is reading directly from the http stream coming from the client. infilename = REQUEST.form['attached_file'].filename # Get filename infile = REQUEST.form['attached_file'] # Get the file descriptor myheader = infile.read(500) # Read up to 500 bytes infile.close() # Close the stream This should be in an external method or product. I haven't tested whether or not this will only let the client upload the first 500 bytes, it's very possible zope takes in the entire file, and puts it into a buffer that is like a file descriptor (hence StringIO). Knight knight@phunc.com On Wed, 11 Oct 2000, Paul Winkler wrote:
Another way to look at it: I want to start uploading the file, but stop the upload almost immediately - after I've got enough to read the file header, but long before the upload would normally finish.
Chris McDonough wrote:
Paul,
I'm sorry if I'm dropping context here, but I'm not sure what you mean when you say "headers of files".
Do you just want to check the size of files before you put them in the ZODB?
That would be useful, but I need more information than that. I need to read some of the file's description of itself that's commonly kept in a header at the beginning of a file.
For example, take a .gif or .jpeg file and throw away all but the first (let's say) 1 kb of the file. If you try to open this truncated file with an image editor (gimp, photoshop, whatever) you'll have problems. But useful information is still stored in that first part of the file, as we can see using python and PIL. Example, on linux:
head --bytes 1000 foo.gif > foo_truncated.gif python ...
import Image test = Image.open('foo_truncated.gif', 'r') test.size (210, 210)
So in this case, we can find out that foo.gif is 210 x 210 pixels even if we only have access to the first 1 kb of the 12 kb file.
If the file in question is 1 MB or so, this trick becomes really useful. Suppose your web application needs an image about 1000 x 1000 pixels. You could warn the user if their image is too small to look good, or so big it's a waste of their time.
So basically what I want to do is start uploading the file, but stop quickly.
Now then, does anyone know how to do it?
Thanks again,
Paul
-- ................. paul winkler .................. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )