Reputation: 12007
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 3200x2400 resolution). Yet, the served image is always 512x384.
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
Upvotes: 1
Views: 625
Reputation: 24956
The explanation for what you're seeing is explained in https://developers.google.com/appengine/docs/python/images/functions
In the doc for get_serving_url
:
When resizing or cropping an image, you must specify the new size using an integer 0 to 1600. The maximum size is defined in IMG_SERVING_SIZES_LIMIT. The API resizes the image to the supplied value, applying the specified size to the image's longest dimension and preserving the original aspect ratio.
An alternative approach, if you want to serve full-sized images, is to upload your images directly to the blobstore, then serve them from there. (I.e., bypass the image API completely.) See https://developers.google.com/appengine/docs/python/blobstore/overview
Upvotes: 0
Reputation: 12007
Found a solution. Or at least something that works for me.
My appending =sXX
onto the end of the served URL, AppEngine will serve the image at the XX
resolution. For instance, if the line:
self.response.out.write(images.get_serving_url( blob_key ))
returns:
http://appengine.sample.com/appengineurlkey
Then 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 1600x1200
resolution (or a similar resolution restricted by maintaining the aspect ratio).
Upvotes: 3