Bird
Raised Fist0
Firebasecloud~10 mins

Uploading files in Firebase - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a reference to the storage location.

Firebase
const storageRef = firebase.storage().ref().[1]('images/photo.jpg');
Drag options to blanks, or click blank then click option'
Aupload
Bchild
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upload' instead of 'child' to create a reference.
Trying to use 'get' or 'delete' before creating the reference.
2fill in blank
medium

Complete the code to upload a file to Firebase Storage.

Firebase
storageRef.[1](file).then(() => console.log('Upload complete'));
Drag options to blanks, or click blank then click option'
AgetDownloadURL
BlistAll
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getDownloadURL' instead of 'put' to upload.
Trying to use 'delete' or 'listAll' which are unrelated to uploading.
3fill in blank
hard

Fix the error in the code to get the download URL after upload.

Firebase
storageRef.put(file).then(() => storageRef.[1]()).then(url => console.log(url));
Drag options to blanks, or click blank then click option'
Adelete
Bupload
Clist
DgetDownloadURL
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upload' again instead of 'getDownloadURL'.
Trying to use 'delete' or 'list' which do not return URLs.
4fill in blank
hard

Fill both blanks to delete a file and then log a success message.

Firebase
storageRef.[1]().then(() => console.log([2]));
Drag options to blanks, or click blank then click option'
Adelete
B'File deleted successfully'
C'Upload complete'
Dput
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'put' instead of 'delete' to remove files.
Logging the wrong message after deletion.
5fill in blank
hard

Fill all three blanks to upload a file, get its URL, and log it.

Firebase
storageRef.[1](file).then(() => storageRef.[2]()).then([3] => console.log([3]));
Drag options to blanks, or click blank then click option'
Aput
BgetDownloadURL
Curl
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up method names or variable names.
Using 'delete' instead of 'put' or 'getDownloadURL'.

Practice

(1/5)
1. What is the main purpose of uploading files to Firebase Storage?
easy
A. To save files in the cloud for easy access and backup
B. To delete files from the user's device
C. To convert files into text format
D. To run files as programs on Firebase servers

Solution

  1. Step 1: Understand file upload purpose

    Uploading files to Firebase Storage means saving them remotely in the cloud.
  2. Step 2: Identify the benefit

    Files saved in the cloud can be accessed anytime and are backed up safely.
  3. Final Answer:

    To save files in the cloud for easy access and backup -> Option A
  4. Quick Check:

    Uploading files = cloud storage [OK]
Hint: Uploading means saving files online for backup and access [OK]
Common Mistakes:
  • Thinking upload deletes local files
  • Confusing upload with file conversion
  • Believing upload runs files on server
2. Which Firebase Storage method is used to create a reference to a file location before uploading?
easy
A. firebase.storage().ref()
B. firebase.storage().upload()
C. firebase.storage().download()
D. firebase.storage().delete()

Solution

  1. Step 1: Identify method to create file location

    firebase.storage().ref() creates a reference to a storage path.
  2. Step 2: Confirm usage before upload

    You must create a reference before uploading a file to specify where it goes.
  3. Final Answer:

    firebase.storage().ref() -> Option A
  4. Quick Check:

    Reference method = ref() [OK]
Hint: Use ref() to point where file will be stored [OK]
Common Mistakes:
  • Using upload() directly without ref()
  • Confusing download() with upload process
  • Trying to delete before uploading
3. What will the following code print if the upload is successful?
const storageRef = firebase.storage().ref('images/photo.jpg');
storageRef.put(file).then(() => console.log('Upload complete')).catch(() => console.log('Upload failed'));
medium
A. Upload failed
B. No output
C. Upload complete
D. SyntaxError

Solution

  1. Step 1: Analyze the upload promise

    storageRef.put(file) returns a promise that resolves on success.
  2. Step 2: Check the then() handler

    On success, it logs 'Upload complete' to the console.
  3. Final Answer:

    Upload complete -> Option C
  4. Quick Check:

    Successful upload logs 'Upload complete' [OK]
Hint: Successful upload triggers then() logging 'Upload complete' [OK]
Common Mistakes:
  • Assuming catch() runs on success
  • Confusing promise syntax
  • Expecting no output on success
4. Identify the error in this Firebase file upload code:
const ref = firebase.storage().ref('docs/report.pdf');
ref.put(file).then(() => console.log('Done'));
console.log('Upload started');
medium
A. console.log('Upload started') should be inside then()
B. ref.put() should be ref.upload()
C. ref() is not a valid method
D. Missing catch() to handle upload errors

Solution

  1. Step 1: Check upload method correctness

    ref.put(file) is correct to upload files in Firebase Storage.
  2. Step 2: Look for error handling

    There is no catch() to handle possible upload failures, which is a best practice.
  3. Final Answer:

    Missing catch() to handle upload errors -> Option D
  4. Quick Check:

    Always add catch() for upload errors [OK]
Hint: Always add catch() after then() to catch errors [OK]
Common Mistakes:
  • Using ref.upload() instead of ref.put()
  • Placing console.log before upload completion
  • Thinking ref() is invalid method
5. You want to upload a user profile picture and ensure the file is stored under 'users/{userId}/profile.jpg'. Which code snippet correctly sets the storage reference and uploads the file for user ID 'abc123'?
hard
A. const ref = firebase.storage().ref('profile.jpg/users/abc123'); ref.put(file);
B. const ref = firebase.storage().ref('users/abc123/profile.jpg'); ref.put(file);
C. const ref = firebase.storage().ref('users/profile.jpg/abc123'); ref.put(file);
D. const ref = firebase.storage().ref('abc123/users/profile.jpg'); ref.put(file);

Solution

  1. Step 1: Understand the required path format

    The file must be stored under 'users/{userId}/profile.jpg', so 'users/abc123/profile.jpg' is correct.
  2. Step 2: Verify the code snippet

    const ref = firebase.storage().ref('users/abc123/profile.jpg'); ref.put(file); uses the correct path and calls ref.put(file) to upload.
  3. Final Answer:

    const ref = firebase.storage().ref('users/abc123/profile.jpg'); ref.put(file); -> Option B
  4. Quick Check:

    Correct path format = users/abc123/profile.jpg [OK]
Hint: Use 'users/{userId}/profile.jpg' path format for user files [OK]
Common Mistakes:
  • Mixing folder order in path
  • Placing userId after filename
  • Using incorrect slashes or order
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard