Home > OS >  Firebase Storage child ref getDownloadURL returning "childPath.split is not a function"
Firebase Storage child ref getDownloadURL returning "childPath.split is not a function"

Time:11-04

The error occurs as a result of the .child(blob), and I've tried:

.child()
.child({blob})
.child(blob.name)

"blob" is defined in earlier parts of the code, it should still be able to refer to it in the storage.

        async function handleSubmitUpload() {
        if (recordedChunks.length) {
            const blob = new Blob(recordedChunks, {
                type: "video/webm",
            });
            await storage().ref(`prodReviews/${blob}`).put(blob);
            console.log( "success storing"   (blob));
            await storage()
                .ref('prodReviews')
                .child(blob)
                .getDownloadURL()
                .then((videoUrl) => {
                    firestore.doc(`products/${productID}`)
                    .set({videoUrl}, { merge: true });
                    console.log("Review for item uploaded successfully")

                        setRecordedChunks([]);
                    })

                }
}

CodePudding user response:

The child() method takes the path of the object as parameter and not a blob. Try refactoring the code as shown below:

// Create a storage reference
const reviewRef = storage().ref(`prodReviews/${blob}`);

// Upload the object to that ref
await reviewRef.put(blob);

// Get download URL
const videoUrl = await videoRef.getDownloadURL();

// Add Firestore document
await firestore.doc(`products/${productID}`).set({videoUrl}, { merge: true });
  • Related