Skip to content

Commit da4d1de

Browse files
fix(storage): set path via 𝘀𝘩π˜ͺ𝘭π˜₯ for π˜₯𝘰𝘸𝘯𝘭𝘰𝘒π˜₯
1️⃣ removes unnecessary param 𝘱𝘒𝘡𝘩 which is need only when having admin access. 2️⃣ resolves need of path to file via 𝘱𝘒𝘡𝘩 param instead of using path built via π’„π’‰π’Šπ’π’… method.
1 parent f7b6e5e commit da4d1de

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

β€Žfirebase/storage/__init__.pyβ€Ž

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def delete(self, name, token):
165165

166166
raise_detailed_error(request_object)
167167

168-
def download(self, path, filename, token=None):
168+
def download(self, filename, token=None):
169169
""" Download file from storage.
170170
171171
| For more details:
@@ -179,9 +179,6 @@ def download(self, path, filename, token=None):
179179
https://firebase.google.com/docs/storage/web/download-files#download_data_via_url
180180
181181
182-
:type path: str
183-
:param path: Path to cloud file
184-
185182
:type filename: str
186183
:param filename: File name to be downloaded as.
187184
@@ -190,28 +187,31 @@ def download(self, path, filename, token=None):
190187
to :data:`None`.
191188
"""
192189

193-
# remove leading backlash
194-
url = self.get_url(token)
190+
if self.credentials:
195191

196-
if path.startswith('/'):
197-
path = path[1:]
192+
# reset path
193+
path = self.path
194+
self.path = None
195+
196+
# remove leading backlash
197+
if path.startswith('/'):
198+
path = path[1:]
198199

199-
if self.credentials:
200200
blob = self.bucket.get_blob(path)
201-
if not blob is None:
201+
if blob is not None:
202202
blob.download_to_filename(filename)
203203

204204
elif token:
205205
headers = {"Authorization": "Firebase " + token}
206-
r = requests.get(url, stream=True, headers=headers)
206+
r = requests.get(self.get_url(token), stream=True, headers=headers)
207207

208208
if r.status_code == 200:
209209
with open(filename, 'wb') as f:
210210
for chunk in r:
211211
f.write(chunk)
212212

213213
else:
214-
r = requests.get(url, stream=True)
214+
r = requests.get(self.get_url(token), stream=True)
215215

216216
if r.status_code == 200:
217217
with open(filename, 'wb') as f:

β€Žtests/test_storage.pyβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under MIT (https://github.com/AsifArmanRahman/firebase/blob/main/LICENSE)
33

44
# --------------------------------------------------------------------------------------
5-
5+
import os.path
66

77
import pytest
88

@@ -18,6 +18,10 @@ def test_put(self, storage):
1818
def test_get_url(self, storage):
1919
assert storage.child('firebase-test-001').child('uploaded-file.txt').get_url(None)
2020

21+
def test_download(self, storage):
22+
assert storage.child('firebase-test-001').child('uploaded-file.txt').download('tests/static/downloaded.txt') is None
23+
assert os.path.exists('tests/static/downloaded.txt')
24+
2125
def test_delete(self, storage):
2226
assert storage.delete('firebase-test-001/uploaded-file.txt', None) is None
2327

0 commit comments

Comments
Β (0)