Stay organized with collections Save and categorize content based on your preferences.
This page describes how to use the Blobstore API, one of the legacy bundled services, with the Python 3 runtime for the standard environment. Your app can access the bundled services through the App Engine services SDK for Python 3.
OverviewSince webapp is not supported in Python 3, you need to make some minimal changes when migrating Blobstore handler code from Python 2 to Python 3. To use the Blobstore API for Python 3, keep in mind the following:
Blobstore handler classes are utility classes. This means that the handler classes are no longer webapp-based, and you cannot use the blobstore_handlers
module provided by the webapp package (google.appengine.ext.webapp
) or the webapp2.RequestHandler
parameters in subclasses of these handlers.
All of the methods in Blobstore handler classes require the WSGI environ
dictionary as an input parameter.
The following sections show how to use BlobstoreUploadHandler
and BlobstoreDownloadHandler
classes for Python 3 in a Flask app and a WSGI app that does not use a Python framework. You can compare the Python 3 examples with the Python 2 example code to learn more about code change differences.
In Python 3, the Blobstore handler classes are part of module google.appengine.ext.blobstore
. For a Flask app, all calls made to methods in BlobstoreUploadHandler
and BlobstoreDownloadHandler
classes require the request.environ
dictionary (request
being imported from the flask
module).
Compare the code changes made from Python 2 (webapp2) to Python 3 (Flask). Notice how the Flask app uses the request.environ
parameter in the methods get_uploads()
and send_blob()
:
class PhotoUploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload = self.get_uploads()[0]
user_photo = UserPhoto(
user=users.get_current_user().user_id(),
blob_key=upload.key())
user_photo.put()
self.redirect('/view_photo/%s' % upload.key())
class ViewPhotoHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, photo_key):
if not blobstore.get(photo_key):
self.error(404)
else:
self.send_blob(photo_key)
app = webapp2.WSGIApplication([
('/', PhotoUploadFormHandler),
('/upload_photo', PhotoUploadHandler),
('/view_photo/([^/]+)?', ViewPhotoHandler),
], debug=True)
Python 3 (Flask)
To view the complete code sample for Python 3 (Flask), see GitHub.
Example: WSGI app without a web frameworkThe following Python 3 (WSGI app) code shows how to add the environ
parameter when using Blobstore handler classes for a WSGI app without a web framework. Notice how the environ
parameter is used in the get_uploads()
and send_blob()
methods, and compare it with the Python 2 version:
class PhotoUploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload = self.get_uploads()[0]
user_photo = UserPhoto(
user=users.get_current_user().user_id(),
blob_key=upload.key())
user_photo.put()
self.redirect('/view_photo/%s' % upload.key())
class ViewPhotoHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, photo_key):
if not blobstore.get(photo_key):
self.error(404)
else:
self.send_blob(photo_key)
app = webapp2.WSGIApplication([
('/', PhotoUploadFormHandler),
('/upload_photo', PhotoUploadHandler),
('/view_photo/([^/]+)?', ViewPhotoHandler),
], debug=True)
Python 3
To view the complete code sample for Python 3, see GitHub.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This document details the use of the Blobstore API with the Python 3 runtime in the standard App Engine environment, accessible via the App Engine services SDK for Python 3."],["Migrating Blobstore handler code from Python 2 to Python 3 requires adjustments, as the handler classes are no longer webapp-based, meaning you can't use the `blobstore_handlers` module from the webapp package."],["In Python 3, all methods within Blobstore handler classes necessitate the WSGI `environ` dictionary as a mandatory input parameter, unlike in Python 2."],["The examples provided illustrate how to use `BlobstoreUploadHandler` and `BlobstoreDownloadHandler` classes within both a Flask application and a WSGI application without a framework, highlighting the use of the `request.environ` parameter."],["Complete Python 3 code samples for both Flask and WSGI app examples are available on GitHub, offering a detailed comparison with their Python 2 counterparts."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4