Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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))
like image 868
voscausa Avatar asked Mar 04 '14 14:03

voscausa


People also ask

Can you run containers on App Engine?

Features. Customizable infrastructure - App Engine flexible environment instances are Compute Engine virtual machines, which means that you can take advantage of custom libraries, use SSH for debugging, and deploy your own Docker containers.


2 Answers

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.

like image 139
voscausa Avatar answered Oct 21 '22 01:10

voscausa


This is the value that you see in the Development mode from app_identity_stub.py:

APP_DEFAULT_GCS_BUCKET_NAME = 'app_default_bucket'

The comments in this file explain it:

This service behaves the same as the production service, except using constant values instead of app-specific values

You should get the correct URL in your production code.

EDIT:

This is from the support forum:

In development mode, the app engine tools simulate Google Cloud Storage services locally. Objects in that simulated environment are non-persistent so your app is failing because the desired object doesn't exist in the local store. If you first create (and optionally write to) the object you're trying to read, it should work fine in dev mode (it did for me). Of course, objects in the production service are persistent so there's no need for that extra step when running your app in production mode (assuming the object already exists).

Hope that helps,

Marc Google Cloud Storage Team

This means you have to write a file first, then you can use it. If I understand correctly, you can use any bucket name for this purpose, including 'app_default_bucket'.

like image 30
Andrei Volgin Avatar answered Oct 21 '22 00:10

Andrei Volgin