On Sun, Oct 4, 2009 at 2:03 PM, Ben <[email protected]> wrote: > > Hi I want to allow users of my application the ability to upload an > image when submitting a form. However i also want to perform a check > on the image to make sure it is less than the 1MB limit BEFORE trying > to put it in the datastore. > > I know i could do: > try: > image.put() > except: > #its to big > > but because of the logic of my application I would like to test the > size of the image BEFORE attempting to put it in the datastore. I > have tried using: > size = os.path.getsize(theImage) > > and > size = os.stat(binaryImage)[ST_SIZE] > > and neither seem to work in the appengine environment. Any ideas?
To get the size of a binary chunk that is already loaded in memory, just do len(image). If image is a class and not a binary chunk, that will not work unless the class has overridden the __len__ operator as appropriate. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
