Search code examples
pythongoogle-app-engineblobstore

Writing files to google app engine blobstore as the methods are going to be deprecated


I want to save some data fetched from the web to blobstore, but the google doc says that

Deprecated: The Files API feature used here to write files to Blobstore is going to be removed at some time in the future, in favor of writing files to Google Cloud Storage and using Blobstore to serve them.

The code in python is as follows

from __future__ import with_statement
from google.appengine.api import files

# Create the file
file_name = files.blobstore.create(mime_type='application/octet-stream')

# Open the file and write to it
with files.open(file_name, 'a') as f:
  f.write('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)

I am wondering if there is another way to write to blobstore instead of the official upload method.


Solution

  • If you want to use a file-like API, you have to go with GCS.

    Blobstore is for uploading more-or-less static images and serving them.

    If you want to write using a a file-like API and then serve from Blobstore, you can write to GCS and get a BlobKey to the file.

    https://cloud.google.com/appengine/docs/python/blobstore/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage

    But writing to BlobStore like you want is deprecated. Stop trying to do it that way.