了解如何使用 Images API 动态地上传、转换、存储和传送图片。此示例介绍了如何在公共留言板上发布消息,以及如何上传带问候语的头像。
在数据存储区中创建图片模型
您需要更新留言板示例中的模型,以将上传的图片存储为 blob。
classGreeting(ndb.Model):"""Models a Guestbook entry with an author, content, avatar, and date."""author=ndb.StringProperty()content=ndb.TextProperty()avatar=ndb.BlobProperty()date=ndb.DateTimeProperty(auto_now_add=True)
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[[["Region IDs are codes assigned by Google based on the selected region when creating an app, and they do not necessarily correspond to country or province codes."],["The Images API allows for the dynamic uploading, transforming, storing, and serving of images, as demonstrated by the example of posting messages and uploading avatars to a public message board."],["To store uploaded images, the Guestbook model in Datastore needs to be updated to include a blob property, enabling users to select files for upload through an HTML form with specific attributes."],["Image transformation involves importing the `google.appengine.api.images` module and using the `resize` function to adjust image dimensions, such as creating 32x32 avatars."],["Deploying the guestbook application to App Engine involves using the `gcloud app deploy app.yaml index.yaml` command, and accessing the deployed application can be done via `gcloud app browse`, noting that Datastore indexes might take time to generate."]]],[]]