Unable to get URL from Firebase's getDownloadURL


Stern Shaw:

I'm using Firebase storage to store images into it, the images are easily uploaded to the storage, but when I try to get the url of the image form Promise, it doesn't return any url.

  const imageSaveHandler = (e) => {
    e.preventDefault();
    const uploadTask = storage.ref(`images/${image.name}`).put(image);
    uploadTask.on(
      "state_changed",
      (error) => {
        console.log(error);
      },
      () => {
        return storage
          .ref(`images/${image.name}`)
          .getDownloadURL()
          .then((url) => {console.log(url)})
          .catch((err) => console.log(err));
      }
    );
  };
Ethan Lipkind:

uploadTask.onAccording to the example in https://firebase.google.com/docs/storage/web/upload-files, the handler currently used as the third parameter should be changed to the fourth parameter :

var uploadTask = storageRef.child('images/rivers.jpg').put(file);

// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// 3. Completion observer, called on successful completion
uploadTask.on('state_changed', function(snapshot){
  // Observe state change events such as progress, pause, and resume
  // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
  var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
  console.log('Upload is ' + progress + '% done');
  switch (snapshot.state) {
    case firebase.storage.TaskState.PAUSED: // or 'paused'
      console.log('Upload is paused');
      break;
    case firebase.storage.TaskState.RUNNING: // or 'running'
      console.log('Upload is running');
      break;
  }
}, function(error) {
  // Handle unsuccessful uploads
}, function() {
  // Handle successful uploads on complete
  // For instance, get the download URL: https://firebasestorage.googleapis.com/...
  uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
    console.log('File available at', downloadURL);
  });
});

Related


Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using Firebase storage to store images into it, the images are easily uploaded to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); c

Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using firebase storage to store images into it, the images are easy to upload to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); co

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager: I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; }

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; } }

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager: I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; }

Unable to get download url from firebase storage

Pannan I can upload the image successfully but can't get the URL of the uploaded image Also with the recent changes to the method I would like to write a cleaner code than this. try { await FirebaseStorage.instance .ref()

Firebase Storage's getDownloadUrl() method cannot be resolved

Neeraj Sewani To upload images to Firebase Storage, attach to a StorageReference instance . When I override the method, the instance I am calling , but it gives me an erroraddOnSuccessListeneronSuccessgetDownloadUrl()taskSnapshot Cannot resolve method getDownl

Firebase Storage's getDownloadUrl() method cannot be resolved

Neeraj Sewani To upload images to Firebase Storage, attach to a StorageReference instance . When I override the method, the instance I am calling , but it gives me an erroraddOnSuccessListeneronSuccessgetDownloadUrl()taskSnapshot Cannot resolve method getDownl