Your files are stored in a Cloud Storage bucket. The files in this bucket are presented in a hierarchical structure, just like the file system on your local hard disk, or the data in the Firebase Realtime Database . By creating a reference to a file, your app gains access to it. These references can then be used to upload or download data, get or update metadata or delete the file. A reference can either point to a specific file or to a higher level node in the hierarchy.
If you've used the Firebase Realtime Database , these paths should seem very familiar to you. However, your file data is stored in Cloud Storage , notin the Realtime Database .
Create a Reference
In order to upload or download files, delete files, or get or update metadata, you must create a reference to the file you want to operate on. A reference can be thought of as a pointer to a file in the cloud. References are lightweight, so you can create as many as you need, and they are also reusable for multiple operations.
To create a reference, get an instance of the Storage service using getStorage()
then call ref()
with the service as an argument.
This reference points to the root of your Cloud Storage
bucket.
Web
import { getStorage , ref } from "firebase/storage" ; // Get a reference to the storage service, which is used to create references in your storage bucket const storage = getStorage (); // Create a storage reference from our storage service const storageRef = ref ( storage );
Web
// Get a reference to the storage service, which is used to create references in your storage bucket var storage = firebase . storage (); // Create a storage reference from our storage service var storageRef = storage . ref ();
You can create a reference to a location lower in the tree,
say 'images/space.jpg'
by passing in this path as a second argument when
calling ref()
.
Web
import { getStorage , ref } from "firebase/storage" ; const storage = getStorage (); // Create a child reference const imagesRef = ref ( storage , 'images' ); // imagesRef now points to 'images' // Child references can also take paths delimited by '/' const spaceRef = ref ( storage , 'images/space.jpg' ); // spaceRef now points to "images/space.jpg" // imagesRef still points to "images"

