Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
    });   
  });
like image 749
swg1cor14 Avatar asked Feb 01 '17 05:02

swg1cor14


People also ask

How do I retrieve files from Firebase Storage?

There are two ways to download files with Firebase Storage, using references in the SDK or a download URL. iOS and Android users can download files into memory, disk, or from a download URL. The web SDK can download files just from a download URL. StorageReference storageRef = FirebaseStorage.

How do I download all files from Firebase Storage?

Once you have a reference, you can download files from Cloud Storage by calling the getBytes() or getStream() . If you prefer to download the file with another library, you can get a download URL with getDownloadUrl() .

How do I upload multiple images to Firebase?

Connect to Firebase gradle file, you can use the Tools menu and select Firebase. This will pop out the Firebase Assistant with a list of menu choices. Scroll down to Storage and add Firebase to your project. Choose an existing project or create a new one then add Firebase Storage dependency.


1 Answers

Use "then" for the second time will fire after the file was successfully uploaded. Sorry for my bad English. https://firebase.google.com/docs/storage/web/upload-files

rainbowPhotoUploader.addEventListener('change', function(e) {

        var file = e.target.files[0];

        var storageRef = firebase.storage().ref('rainbow_photos/' + file.name);

        storageRef.put(file).then(function(snapshot) {

            // 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');

        }).then(function() {
            // Upload completed successfully, now we can get the download URL
            storageRef.getDownloadURL().then(function(downloadURL) {
                console.log('File available at', downloadURL);
            });
        });
    });
like image 89
Suhail Kawsara Avatar answered Sep 29 '22 22:09

Suhail Kawsara