Skip to content

Commit 2708a59

Browse files
docs: add Storage guide
1 parent 473c9d1 commit 2708a59

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

docs/guide/firebase-rest-api.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ A Firebase app can use multiple Firebase services.
126126

127127
``firebaseApp.database()`` - :ref:`Database<guide/database:Database>`
128128

129-
``firebaseApp.storage()`` - `Storage`
129+
``firebaseApp.storage()`` - :ref:`Storage<guide/storage:Storage>`
130130

131131
Check out the documentation for each service for further details.
132-

docs/guide/storage.rst

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Storage
2+
=======
3+
4+
The storage service allows you to upload files (eg. text, image,
5+
video) to Firebase.
6+
7+
child
8+
-----
9+
10+
Just like with the Database service, you can build paths to your data
11+
with the Storage service.
12+
13+
.. code-block:: python
14+
15+
storage.child("images/example.jpg")
16+
..
17+
18+
put
19+
---
20+
21+
The put method takes the path to the local file and an optional user
22+
token.
23+
24+
.. code-block:: python
25+
26+
storage = firebaseApp.storage()
27+
# as admin
28+
storage.child("images/example.jpg").put("example2.jpg")
29+
# as user
30+
storage.child("images/example.jpg").put("example2.jpg", user['idToken'])
31+
..
32+
33+
download
34+
--------
35+
36+
The download method takes the path to the saved database file and the
37+
name you want the downloaded file to have.
38+
39+
.. code-block:: python
40+
41+
storage.child("images/example.jpg").download("downloaded.jpg")
42+
..
43+
44+
get_url
45+
-------
46+
47+
The get_url method takes the path to the saved database file and user
48+
token which returns the storage url.
49+
50+
.. code-block:: python
51+
52+
storage.child("images/example.jpg").get_url(user["idToken"])
53+
# https://firebasestorage.googleapis.com/v0/b/storage-url.appspot.com/o/images%2Fexample.jpg?alt=media
54+
..
55+
56+
delete
57+
------
58+
59+
The delete method takes the path to the saved database file and user
60+
token.
61+
62+
.. code-block:: python
63+
64+
storage.delete("images/example.jpg",user["idToken"])
65+
..
66+
67+
68+
Helper Methods
69+
--------------
70+
71+
generate_key
72+
^^^^^^^^^^^^
73+
74+
``db.generate_key()`` is an implementation of Firebase's `key generation
75+
algorithm <https://www.firebase.com/blog/2015-02-11-firebase-unique-identifiers.html>`__.
76+
77+
See multi-location updates for a potential use case.
78+
79+
80+
sort
81+
^^^^
82+
83+
Sometimes we might want to sort our data multiple times. For example, we
84+
might want to retrieve all articles written between a certain date then
85+
sort those articles based on the number of likes.
86+
87+
Currently the REST API only allows us to sort our data once, so the
88+
``sort()`` method bridges this gap.
89+
90+
.. code-block:: python
91+
92+
articles = db.child("articles").order_by_child("date").start_at(startDate).end_at(endDate).get()
93+
articles_by_likes = db.sort(articles, "likes")
94+
..
95+
96+
97+
Common Errors
98+
-------------
99+
100+
Index not defined
101+
^^^^^^^^^^^^^^^^^
102+
103+
+`Indexing<https://firebase.google.com/docs/database/security/indexing-data>`__
104+
is **not enabled** for the database reference.

0 commit comments

Comments
 (0)