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

2007-07-01 Thread Diez B. Roggisch
> 
> 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.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2007-06-30 Thread Evan Klitzke
On 6/30/07, Cameron Laird <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
> Evan Klitzke <[EMAIL PROTECTED]> wrote:
> >On 6/30/07, Norman Khine <[EMAIL PROTECTED]> wrote:
> >> Hello,
> >> I am writing an application using python that allows the user to upload
> >> an image to a folder on the server.
> >>
> >> 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.
> >
> >The easiest way to do this is to simply restrict the maximum file
> >upload size. When the client makes the POST request you can see how
> >big it will be. This won't really give you the image dimensions of
> >course, but there's no simple way to find out that information without
> >uploading the entire image.
> .
> .
> .
> Maybe we disagree about "simple", but there *are* definite
> ways to do so.  It's a bit involved--I fear that when Mr.
> Khine writes "image", he might have in mind not just .gif,
> .jpg, and .png, but perhaps also SVG, Flash, PDF, ...--but,
> yes, it's possible with most image formats to upload just a
> small portion of the header and test whether what follows
> meets the size requirements.

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).

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2007-06-30 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Evan Klitzke <[EMAIL PROTECTED]> wrote:
>On 6/30/07, Norman Khine <[EMAIL PROTECTED]> wrote:
>> Hello,
>> I am writing an application using python that allows the user to upload
>> an image to a folder on the server.
>>
>> 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.
>
>The easiest way to do this is to simply restrict the maximum file
>upload size. When the client makes the POST request you can see how
>big it will be. This won't really give you the image dimensions of
>course, but there's no simple way to find out that information without
>uploading the entire image.
.
.
.
Maybe we disagree about "simple", but there *are* definite
ways to do so.  It's a bit involved--I fear that when Mr. 
Khine writes "image", he might have in mind not just .gif,
.jpg, and .png, but perhaps also SVG, Flash, PDF, ...--but,
yes, it's possible with most image formats to upload just a
small portion of the header and test whether what follows
meets the size requirements.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2007-06-30 Thread Evan Klitzke
On 6/30/07, Norman Khine <[EMAIL PROTECTED]> wrote:
> Hello,
> I am writing an application using python that allows the user to upload
> an image to a folder on the server.
>
> 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.

The easiest way to do this is to simply restrict the maximum file
upload size. When the client makes the POST request you can see how
big it will be. This won't really give you the image dimensions of
course, but there's no simple way to find out that information without
uploading the entire image.

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2007-06-30 Thread Norman Khine
Hello,
I am writing an application using python that allows the user to upload
an image to a folder on the server.

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.

So far, my apps loads the image and checks it and then returns an error
if the image is too big.  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

-- 
http://mail.python.org/mailman/listinfo/python-list