[Zope] Re: Upload just file headers?

Paul Winkler slinkp23@yahoo.com
Wed, 11 Oct 2000 15:54:17 -0400


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