Skip to content

Commit

Permalink
add storage download without service account
Browse files Browse the repository at this point in the history
  • Loading branch information
thisbejim committed Nov 10, 2016
1 parent 98749d0 commit ec78787
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pyrebase/pyrebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,22 @@ def put(self, file, token=None):
def delete(self, name):
self.bucket.delete_blob(name)

def download(self, filename):
def download(self, filename, token=None):
# remove leading backlash
path = self.path
url = self.get_url(token)
self.path = None
if path.startswith('/'):
path = path[1:]
blob = self.bucket.get_blob(path)
blob.download_to_filename(filename)
if self.credentials:
blob = self.bucket.get_blob(path)
blob.download_to_filename(filename)
else:
r = requests.get(url, stream=True)
if r.status_code == 200:
with open(filename, 'wb') as f:
for chunk in r:
f.write(chunk)

def get_url(self, token):
path = self.path
Expand Down

0 comments on commit ec78787

Please sign in to comment.