Reading image dimensions before it is loaded from a web form using python.

Diez B. Roggisch deets at
Sun Jul 1 13:25:49 CEST 2007

> Without running some special client-side application, I think you'd
> have to do some trickery with the web server involving artificially
> stopping the upload after receiving enough bytes to constitute the
> image header, and then deciding whether or not to proceed with the
> upload at that point. I think that this is definitely nontrivial since
> it would most likely involve some hacking of Apache (or whatever web
> server you are using).

Certainly not. The upload is a simple HTTP POST request, and it's dealt 
by with your application. For example, you could put a simple CGI script 
behind a certain url, and once it has read a few bytes or KBytes from 
stdin, it will test for compliance.

Admittedly, most people use some webframework - which usually abstracts 
away the uploading and passes some  file-like object to you when the 
upload is finished.

But then it's an extension to that framework, and given the fact that 
most of these support out of the box file upload meters, or at least 
there are recipies how to do so, things should work pretty easy.


More information about the Python-list mailing list