0

How to get data URL from snapshot after uploading to storage in firebase, I cannot find the link in the snapshot, there must be another method to complete the action.

  if (input?.files![0]) {
        const storage = getStorage();
        const storageRef = ref(storage, `profiles/${_authContext.currentUser.uid}/${input?.files![0].name}`);
        // 'file' comes from the Blob or File API
        uploadBytes(storageRef, input?.files![0]).then((snapshot) => {
          console.log(snapshot);
          console.log('Uploaded a blob or file!');
        });
      }

1 Answer 1

3

There is another thing you have to do. It's covered in the documentation. Use getDownloadUrl().

getDownloadURL(ref(storage, 'images/stars.jpg'))
  .then((url) => {
    // `url` is the download URL for 'images/stars.jpg'
  }

You can only do this after the upload fully complete.

Sign up to request clarification or add additional context in comments.

1 Comment

So, should it always be done this way to get the url of an img uploaded to storage?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.