[Tutor] Reading image dimensions before it is loaded from a web form using python.
Kent Johnson
kent37 at tds.net
Sat Jun 30 03:02:57 CEST 2007
Norman Khine wrote:
> Hello,
> I am writing an application that allows the user to upload an image to
> their folder.
> Is there a way to get the size of the file before it has been uploaded
> onto the server and give an error if the size does not comply to the
> maximum size.
I'm not at all clear what your environment is. Is you application
running on the computer where the image originates, or on the server? If
your app is running on the source computer then you can just check the
file size. If you have a web app and you are uploading from the browser
then I don't know how to check. The trick in the email you reference
might work.
Kent
>
> So far, my apps loads the image and checks it and then returns the
> error. Which is a bit pointless in that I should be able to get the file
> info before it is loaded, but I am not sure where to go.
>
> PIL reads the image size before it is loaded, but this is when I run
> this on my local machine. There is also a post
> http://mail.python.org/pipermail/python-list/2005-May/323018.html by
> Will McGugan where he loads 1px and rejects it if its too big. But his
> apps is an image scraper, so I suppose it fits his use case where he
> checks the size and then pulls the image if it fits.
>
> Anyone with ideas on how to deal with this.
>
> Thanks
>
> Norman
>
>
More information about the Tutor
mailing list