This code shows how to read and write blobs and how to create a serving url.
The blobfiles can be images or other files like css, js and pdf's.
We use the default bucket in Google Cloud Storage (GCS) to store the blobs.
From the docs: An application can use the default GCS bucket, which provides an already configured bucket with free quota.
This code still needs the blobstore.create_gs_key() for images.get_serving_url()
We use an image serving url for dynamic resizing and cropping.
gcs_upload contains the code to upload a file to cloudstorage, using static html for the form:
upload: https://appid.appspot.com/static/gcs_upload.html
The upload limit is 32 megabytes, because the example code does not use the blobstore create_upload_url callback.
To serve the data, you can use in your Jinja HTML template:
js: <script type="text/javascript" src="{{ serving_url }}"></script>
css: <link type="text/css" rel="stylesheet" href="{{ serving_url }}">
pdf: <a href="{{ serving_url }}" target="_blank">Test PDF</a>
img: <img alt="{{ filename }}" src="{{ serving_url }}" />
In GAE production the serving url looks like:
images: https://lhN.ggpht.com/NlCARAtN.........3NQW9ZxYpms=s698
other: https://storage.googleapis.com/default_bucket/file_name
And in the SDK:
images: http://localhost:8080/_ah/img/encoded_gs_file:YXBwX2R......Y3Nz
other: https://localhost:8080/_ah/gcs/default_bucket/file_name
The SDK encoded_gs_file id = base64.urlsafe_b64encode(app_default_bucket/filename)
This code was tested using App Engine 1.9.6 and the GCS client library
To install the client library on Windows 7 in my project, I used:
C:\Python27\scripts>pip install setuptools --no-use-wheel --upgrade
C:\Python27\scripts>pip install GoogleAppEngineCloudStorageClient -t <my_app_directory_root>