I am successfully posting an image to my Google AppEngine application using the following code:
def post(self):
image_data = self.request.get('file')
file_name = files.blobstore.create(mime_type='image/png')
# Open the file and write to it
with files.open(file_name, 'a', exclusive_lock=True) as f:
f.write(image_data)
# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)
self.response.out.write(images.get_serving_url( blob_key ))
However, when I browse the the URL outputted by get_serving_url(), the image is always at a reduced resolution. Why? I’ve checked and double checked that the image being posted is of the correct size (from an iPhone camera, so approx 3200×2400 resolution). Yet, the served image is always 512×384.
I’m fairly new to GAE, but I thought that the code above should store the image in the BlobStore rather than the datastore, circumventing the 1 MB limit.
Does anyone have any idea what could be going on?
Cheers,
Brett
Found a solution. Or at least something that works for me.
My appending
=sXXonto the end of the served URL, AppEngine will serve the image at theXXresolution. For instance, if the line:self.response.out.write(images.get_serving_url( blob_key ))returns:
http://appengine.sample.com/appengineurlkeyThen when calling the url above results, the image will be a lower resolution image,
Then by calling the URL:
http://appengine.sample.com/appengineurlkey**=s1600**the resulting served image will be at
1600x1200resolution (or a similar resolution restricted by maintaining the aspect ratio).