How to read a Google Cloud Storage file from Google App Engine

Ali Khosro

How do you open a file (from App Engine) that's stored in Google Cloud Storage?

I am using Python, Flask and App Engine (Flexible environment). The file is not public, the bucket belongs to the App Engine project, so has the correct permissions set.

app.yaml

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT view:app
runtime_config:
  python_version: 3.5
env_variables:
    CLOUD_STORAGE_BUCKET: <project-xxxx>

view.py

...
from google.cloud import storage 
gcs = storage.Client()

@app.route('/start_serving/<file_name>')
def start(file_name):
    WHAT TO DO HERE?

#Rest of the app

Thank you in advance. I couldn't find anything related in documentation. It provides information on how to create a bucket, how to upload, how to download, how to give permission, but nothing about how to read it.

Also, how can I open it from my computer (before running the 'gcloud app deploy' command)?

Alex

I have a python2.7 flex app, where I upload to GCS using blob.upload_from_string() but it looks like there is a blob.download_as_string() so maybe something like this would work

from google.cloud import storage

project_id = os.environ['GCLOUD_PROJECT']
CLOUD_STORAGE_BUCKET = "%s.appspot.com" % project_id

@app.route('/start_serving/<file_name>')
def start(file_name):
    gcs = storage.Client()
    bucket = gcs.get_bucket(CLOUD_STORAGE_BUCKET)
    blob = bucket.blob(file_name)
    return blob.download_as_string()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Google Cloud Storage Object Read/Write Operation from App Engine

From Dev

Google Cloud: Storage and App Engine

From Dev

Google cloud storage with app engine

From Dev

How do I write a file through my app in the Google App Engine to the Google Cloud Storage?

From Dev

PHP code to Read excel file uploaded to google app engine cloud storage bucket

From Dev

How to compress google cloud storage files ? google app engine

From Dev

Google App Engine: How to serve uploaded images in a PHP loop from google cloud storage

From Dev

Get Public URL for File - Google Cloud Storage - App Engine (Python)

From Dev

How to read data from Google storage cloud to Google cloud datalab

From Dev

Reading of a file from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app

From Dev

Can't include from Google Cloud Storage with App Engine?

From Dev

Access google cloud storage account objects from app engine

From Dev

How to properly upload (image) file to Google Cloud Storage using Java App Engine?

From Dev

How to decrypt file from Google Cloud Storage?

From Dev

How to load a file from google cloud storage to google cloud function

From Dev

How can I load Jinja2 templates dynamically from Google Cloud Storage in App Engine?

From Dev

Google Cloud App Engine - Default Storage Buckets

From Dev

Google Cloud Storage thru App Engine pricing

From Dev

How to allow a user to download a Google Cloud Storage file from Compute Engine without public access

From Dev

How to transfer a file from Google Cloud Storage to Compute Engine instance using gcloud terminal?

From Dev

How to use file from Google Cloud Storage bucket in Earth Engine? Don't see in Assets

From Dev

Uploading a JSON file with Pyrebase to Firebase Storage from Google App Engine

From Dev

How to get uploaded file URL from Google Cloud Storage by Google App Script

From Dev

How to get public link for the uploaded file on google cloud storage in local dev server(Google App engine+JAVA)

From Dev

google ml-engine cloud storage as a file

From Java

GCS - Read a text file from Google Cloud Storage directly into python

From Dev

Read JSON file content from google cloud storage bucket

From Dev

Read/download part of file from google cloud storage in java

From Dev

Read JSON file directly from google storage (using Cloud Functions)

Related Related

  1. 1

    Google Cloud Storage Object Read/Write Operation from App Engine

  2. 2

    Google Cloud: Storage and App Engine

  3. 3

    Google cloud storage with app engine

  4. 4

    How do I write a file through my app in the Google App Engine to the Google Cloud Storage?

  5. 5

    PHP code to Read excel file uploaded to google app engine cloud storage bucket

  6. 6

    How to compress google cloud storage files ? google app engine

  7. 7

    Google App Engine: How to serve uploaded images in a PHP loop from google cloud storage

  8. 8

    Get Public URL for File - Google Cloud Storage - App Engine (Python)

  9. 9

    How to read data from Google storage cloud to Google cloud datalab

  10. 10

    Reading of a file from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app

  11. 11

    Can't include from Google Cloud Storage with App Engine?

  12. 12

    Access google cloud storage account objects from app engine

  13. 13

    How to properly upload (image) file to Google Cloud Storage using Java App Engine?

  14. 14

    How to decrypt file from Google Cloud Storage?

  15. 15

    How to load a file from google cloud storage to google cloud function

  16. 16

    How can I load Jinja2 templates dynamically from Google Cloud Storage in App Engine?

  17. 17

    Google Cloud App Engine - Default Storage Buckets

  18. 18

    Google Cloud Storage thru App Engine pricing

  19. 19

    How to allow a user to download a Google Cloud Storage file from Compute Engine without public access

  20. 20

    How to transfer a file from Google Cloud Storage to Compute Engine instance using gcloud terminal?

  21. 21

    How to use file from Google Cloud Storage bucket in Earth Engine? Don't see in Assets

  22. 22

    Uploading a JSON file with Pyrebase to Firebase Storage from Google App Engine

  23. 23

    How to get uploaded file URL from Google Cloud Storage by Google App Script

  24. 24

    How to get public link for the uploaded file on google cloud storage in local dev server(Google App engine+JAVA)

  25. 25

    google ml-engine cloud storage as a file

  26. 26

    GCS - Read a text file from Google Cloud Storage directly into python

  27. 27

    Read JSON file content from google cloud storage bucket

  28. 28

    Read/download part of file from google cloud storage in java

  29. 29

    Read JSON file directly from google storage (using Cloud Functions)

HotTag

Archive