Region ID
The REGION_ID
is an abbreviated code that Google assigns
based on the region you select when you create your app. The code does not
correspond to a country or province, even though some region IDs may appear
similar to commonly used country and province codes. For apps created after
February 2020, REGION_ID.r
is included in
App Engine URLs. For existing apps created before this date, the
region ID is optional in the URL.
Learn more about region IDs.
Learn how to upload, transform, store, and serve images dynamically using the Images API. This example describes how to post messages to a public message board and upload an avatar with your greeting.
Creating an Image model in Datastore
You need to update the model from the guestbook sample to store the uploaded image as a blob.
Uploading user images
You will need to modify the HTML form to enable the user to upload an image:
Add a field that enables the user to select a file from their computer to upload.
Add the
enctype
attribute to the form tag and specify this is a multi-part form post.Update the Guestbook handler to get the image data from the form post and store it as a blob in the datastore.
Transforming images
To create 32x32 avatars you will need to:
Import the
google.appengine.api.images
module.Call the
resize
function and pass in the image data.
Dynamically serving images
To serve images, you will need to:
Create an image handler that dynamically serves images off the
/img
path.Update the HTML to display these dynamically served images.
You will need to update the Guestbook's HTML to pass the key of the greeting to the image handler as
it gets the img_id
from the request.
Deploying the app to App Engine
To upload the guestbook app, run the following command from within the
guestbook
directory of your application where the app.yaml
and
index.yaml
files are located:
gcloud app deploy app.yaml index.yaml
The Datastore indexes might take some time to
generate before your application is available. If the indexes are still in the
process of being generated, you will receive a NeedIndexError
message when accessing your app. This error is transient, so try a little later
if at first you receive this error.
To learn more about deploying your app from the command line, see Deploying A Python App.
Viewing your deployed application
To launch your browser and view the app at
https://PROJECT_ID.REGION_ID.r.appspot.com
, run the following command:
gcloud app browse