Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage.list_files() fetches all files from Firebase storage. How to list/get files from a specific path only. #305

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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)
```

Expand Down Expand Up @@ -227,23 +227,23 @@ 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"}}
```

#### key
Calling ```key()``` returns the key for the query data.

```
```python
user = db.child("users").get()
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
Expand Down Expand Up @@ -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")
```

Expand Down Expand Up @@ -383,19 +383,27 @@ 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")
```

### get_url

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
```
Expand Down
4 changes: 2 additions & 2 deletions pyrebase/pyrebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down