pythongoogle-app-enginesdkgoogle-cloud-storageserving

How to serve cloudstorage files using app engine SDK


In app engine I can serve cloudstorage files like a pdf using the default bucket of my application:

http://storage.googleapis.com/<appid>.appspot.com/<file_name>

But how can I serve local cloudstorage files in the SDK, without making use of a blob_key?

I write to the default bucket like this:

gcs_file_name = '/%s/%s' % (app_identity.get_default_gcs_bucket_name(), file_name)
with gcs.open(gcs_file_name, 'w') as f:
    f.write(data)

The name of the default bucket in the SDK = 'app_default_bucket'

In the SDK datastore I have a Kind: GsFileInfo showing: filename: /app_default_bucket/example.pdf

Update and workaround: You can get a serving url for NON image files like css, js and pdf.

gs_file = '/gs/%s/%s/%s' % (app_identity.get_default_gcs_bucket_name(), folder, filename)
serving_url = images.get_serving_url(blobstore.create_gs_key(gs_file))

Solution

  • UPDATE I found this feature to serve cloudstorage files using the SDK:

    This feature has not been documented yet.

    http://localhost:8080/_ah/gcs/app_default_bucket/filename
    

    This meands we do not need the img serving url to serve NON images as shown below !!!

    To create e serving url for cloudstorage files like images, css, js and pdf's in the default_bucket, I use this code for testing(SDK) and GAE production:

    IMPORTANT: the images.get_serving_url() works also for NON images in the SDK!!

    In the SDK you stll need the blobstore to read a blob and create a serving url for a cloudstorage object.

    I also added the code to read, write and upload cloudstorage blobs in the SDK and GAE production.

    The code can be found here.