0
votes

I'm newbie here on GCS. & trying to read & download files from GCS.

Here i wrote few lines.

from google.appengine.api import files

def download_data_from_gcs(request):
    file_name = '/gs/bucket-name-1/new_file.csv' # change bucket/object names to suit your needs
    with files.open(file_name, 'r') as f:
        data = f.read()
        logging.error(data) # I'm getting here csv data. Its around of ~20-25 MB

Now tricky part is to download this data as is. Ex. new_file.csv

Has someone worked around it? Would appreciate that way.

Thanks

1
Where are you trying to download it to? To the App Engine app, for use within the code, or to the end client?Daniel Roseman
@DanielRoseman: It would be great if we could download it at client end.Niks Jain

1 Answers

1
votes

Can't you just download it directly from the URL?

https://storage.cloud.google.com/bucket-name-1/new_file.csv

If that required Google login, then it used the default ACL from the bucket the file is in.

When you write your file to gcs, you can set ACL (permissions) for the file to public in the options dictionary:

gcs_file = cloudstorage.open(filename, 'w', content_type='text/plain', options={'x-goog-acl': 'public-read'})