user2965235
user2965235

Reputation: 1

How to download a file from the Google Cloud?

How can I download a file from the cloud? The file is saved on the cloud and I want to download it through an app engine web application. Is there a function for this task? I want to save a file to my PC. I tried really hard to find the answer for this question, but I didn't find anything.

Thanks for your replies :-)

Upvotes: 0

Views: 368

Answers (1)

Paul Collingwood
Paul Collingwood

Reputation: 9116

You can query the contents of a cloud bucket like this (shortened example)

https://developers.google.com/appengine/docs/python/googlecloudstorageclient/

 """A sample app that uses GCS client to operate on bucket and file."""

import os
import cloudstorage as gcs
import webapp2


BUCKET = '/yey-cloud-storage-trial'


class MainPage(webapp2.RequestHandler):
    def list_bucket_directory_mode(self, bucket):
        self.response.write('\nListbucket directory mode result:\n')
        for stat in gcs.listbucket(bucket + '/b', delimiter='/'):
          self.response.write('%r' % stat)
          self.response.write('\n')
          if stat.is_dir:
            for subdir_file in gcs.listbucket(stat.filename, delimiter='/'):
              self.response.write('  %r' % subdir_file)
              self.response.write('\n')

You can see the full code here: https://developers.google.com/appengine/docs/python/googlecloudstorageclient/getstarted

You can then read the file with the def read_file method as shown on that linked page and return it to the user in the response. So file from GSC-->GAE-->User.

Upvotes: 1

Related Questions