firebasefirebase-storage

Firebase Storage Put could not get object


Using the WEB version of the SDK to store an image to Firebase Storage. File DOES get uploaded but keep getting the following message when trying to get the download URL

code:"storage/object-not-found"
message:"Firebase Storage: Object 'rainbow_photos/daniel.jpg' does not exist."
name:"FirebaseError"
serverResponse:"{↵  "error": {↵    "code": 404,↵    "message": "Not Found.  Could not get object"↵  }↵}"

But the file daniel.jpg DOES get stored in the rainbow_photos folder.

Here's how we are putting the file:

rainbowPhotoUploader.addEventListener('change', function(e){
    //Get file
    var file = e.target.files[0];
    //Create a storage ref
    var storageRef = firebase.storage().ref('rainbow_photos/' + file.name);
    //Upload file
    storageRef.put(file);
    //Get URL and store to pass
    storageRef.getDownloadURL().then(function(result){
        $('#rainbowPhotoURL').val(result);
    });   
  });

Solution

  • Basically what Austin said, except we're smart (we are, trust me!) and we'll return the download URL in the promise after upload so you don't have to do the second fetch:

    rainbowPhotoUploader.addEventListener('change', function(e){
      //Get file
      var file = e.target.files[0];
      //Create a storage ref
      var storageRef = firebase.storage().ref('rainbow_photos/' + file.name);
      //Upload file
      storageRef.put(file).then(function(snapshot){
        $('#rainbowPhotoURL').val(snapshot.downloadURL);
      });
    });