0
0
Firebasecloud~10 mins

Why file storage is needed in Firebase - Visual Breakdown

Choose your learning style9 modes available
Process Flow - Why file storage is needed
User wants to save a photo
App sends photo to cloud storage
Cloud stores photo safely
User or app retrieves photo later
Photo is displayed or used in app
This flow shows how file storage lets users save and get files like photos safely in the cloud.
Execution Sample
Firebase
const storageRef = firebase.storage().ref('images/photo.jpg');
storageRef.put(file).then(() => console.log('Uploaded'));
This code uploads a photo file to Firebase cloud storage under 'images/photo.jpg'.
Process Table
StepActionInput/ConditionResultNotes
1Create storage reference'images/photo.jpg'Reference to storage location createdSets where file will be saved
2Upload fileFile object from userFile is sent to cloud storageFile data is transferred
3Upload completesUpload successFile stored safely in cloudFile is now accessible later
4Retrieve fileRequest file by pathFile data returnedFile can be used/displayed
5Display fileFile data receivedPhoto shown in appUser sees their photo
💡 File is stored and can be retrieved anytime, enabling persistent access.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
storageRefundefinedReference to 'images/photo.jpg'SameSameSameSame
fileUser file inputSameUploadingUploadedAvailableAvailable
uploadStatusNot startedNot startedIn progressCompletedCompletedCompleted
retrievedFileNoneNoneNoneNoneFile dataFile data
Key Moments - 3 Insights
Why do we need a storage reference before uploading?
The storage reference tells Firebase where to save the file. Without it, Firebase won't know the file's location. See execution_table step 1.
What happens if the upload fails?
If upload fails, the file won't be stored and can't be retrieved later. The uploadStatus would not reach 'Completed'. See execution_table step 3.
Why can't we display the photo before retrieving it?
The app needs the file data from storage to show the photo. Without retrieval, there's no data to display. See execution_table step 4 and 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of 'uploadStatus' after step 2?
ANot started
BCompleted
CIn progress
DFailed
💡 Hint
Check the 'uploadStatus' variable in variable_tracker after step 2.
At which step does the file become available for retrieval?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Look at execution_table where upload completes and file is stored.
If the storage reference was not created, what would happen?
AUpload fails because no path is set
BFile uploads to default location
CFile is stored locally only
DFile is automatically named
💡 Hint
Refer to key_moments about the importance of storage reference.
Concept Snapshot
Why file storage is needed:
- Files like photos need a safe place to live.
- Cloud storage saves files so apps can access anytime.
- Use a storage reference to set file location.
- Upload sends file to cloud.
- Retrieve to use or show file later.
Full Transcript
File storage is needed to save files like photos safely in the cloud. The app creates a storage reference to tell Firebase where to save the file. Then it uploads the file data. Once uploaded, the file is stored and can be retrieved anytime. Retrieval gets the file data so the app can display or use it. Without file storage, files would be lost or only on one device. This flow ensures files persist and are accessible from anywhere.