From d01d710ca5a8f856a6014f0e7fa44bbdec929711 Mon Sep 17 00:00:00 2001 From: Anirudh Sharma Date: Thu, 13 Jun 2019 00:59:06 +0530 Subject: [PATCH 1/2] Add optional prefix argument to list_files() in Storage storage.list_files() fetches all the records from Firebase storage. Add optional prefix argument to list_files() in Storage to fetch records only from a specific path. eg. storage.list_files(prefix="images/paul") --- pyrebase/pyrebase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrebase/pyrebase.py b/pyrebase/pyrebase.py index bc1fc3e..499d1f9 100644 --- a/pyrebase/pyrebase.py +++ b/pyrebase/pyrebase.py @@ -435,8 +435,8 @@ def get_url(self, token): return "{0}/o/{1}?alt=media&token={2}".format(self.storage_bucket, quote(path, safe=''), token) return "{0}/o/{1}?alt=media".format(self.storage_bucket, quote(path, safe='')) - def list_files(self): - return self.bucket.list_blobs() + def list_files(self, prefix=None): + return self.bucket.list_blobs(prefix=prefix) def raise_detailed_error(request_object): From 0e81a7d4ae3839be963bcde5fc9b40d4a729c1ec Mon Sep 17 00:00:00 2001 From: Anirudh Sharma Date: Thu, 13 Jun 2019 01:29:37 +0530 Subject: [PATCH 2/2] add delete() documentation Add delete() documentation of Firebase storage --- README.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cdc610b..cf28982 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ results = db.child("users").push(data, user['idToken']) ### Token expiry A user's idToken expires after 1 hour, so be sure to use the user's refreshToken to avoid stale tokens. -``` +```python user = auth.sign_in_with_email_and_password(email, password) # before the 1 hour expiry: user = auth.refresh(user['refreshToken']) @@ -102,15 +102,15 @@ user['idToken'] ### Custom tokens You can also create users using [custom tokens](https://firebase.google.com/docs/auth/server/create-custom-tokens), for example: -``` +```python token = auth.create_custom_token("your_custom_id") ``` You can also pass in additional claims. -``` +```python token_with_additional_claims = auth.create_custom_token("your_custom_id", {"premium_account": True}) ``` You can then send these tokens to the client to sign in, or sign in as the user on the server. -``` +```python user = auth.sign_in_with_custom_token(token) ``` @@ -227,7 +227,7 @@ db.update(data) #### val Queries return a PyreResponse object. Calling ```val()``` on these objects returns the query data. -``` +```python users = db.child("users").get() print(users.val()) # {"Morty": {"name": "Mortimer 'Morty' Smith"}, "Rick": {"name": "Rick Sanchez"}} ``` @@ -235,7 +235,7 @@ print(users.val()) # {"Morty": {"name": "Mortimer 'Morty' Smith"}, "Rick": {"nam #### key Calling ```key()``` returns the key for the query data. -``` +```python user = db.child("users").get() print(user.key()) # users ``` @@ -243,7 +243,7 @@ print(user.key()) # users #### each Returns a list of objects on each of which you can call ```val()``` and ```key()```. -``` +```python all_users = db.child("users").get() for user in all_users.each(): print(user.key()) # Morty @@ -287,7 +287,7 @@ You should at least handle `put` and `patch` events. Refer to ["Streaming from t You can also add a ```stream_id``` to help you identify a stream if you have multiple running: -``` +```python my_stream = db.child("posts").stream(stream_handler, stream_id="new_posts") ``` @@ -383,11 +383,19 @@ storage.child("images/example.jpg").put("example2.jpg") storage.child("images/example.jpg").put("example2.jpg", user['idToken']) ``` +### delete + +The delete method takes the path to the saved database file. + +```python +storage.delete("images/example.jpg") +``` + ### download The download method takes the path to the saved database file and the name you want the downloaded file to have. -``` +```python storage.child("images/example.jpg").download("downloaded.jpg") ``` @@ -395,7 +403,7 @@ storage.child("images/example.jpg").download("downloaded.jpg") The get_url method takes the path to the saved database file and returns the storage url. -``` +```python storage.child("images/example.jpg").get_url() # https://firebasestorage.googleapis.com/v0/b/storage-url.appspot.com/o/images%2Fexample.jpg?alt=media ```