【问题标题】:Firebase Storage child ref getDownloadURL returning "childPath.split is not a function"Firebase 存储子引用 getDownloadURL 返回“childPath.split 不是函数”
【发布时间】:2021-12-18 03:23:15
【问题描述】:

由于 .child(blob) 而发生错误,我已经尝试过:

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

“blob”在代码的前面部分定义,它应该仍然可以在存储中引用它。

        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([]);
                    })

                }
}

【问题讨论】:

  • blob 到底是什么? child() 方法需要一个字符串。您是否尝试获取已上传对象的下载 URL?
  • 是的,blob 在之前的代码中已上传到 Storage。只是现在我想要downloadURL,这样视频就可以存储在Firebase上并显示在项目中
  • 你能分享你用来上传文件的代码吗?您必须在child() 中使用相同的路径才能获取该对象的信息。或者您可以从快照本身获取参考
  • 我刚刚编辑了帖子以包含完整的代码。我没有“快照”的代码,我认为不需要

标签: javascript firebase firebase-storage


【解决方案1】:

child() 方法将对象的路径作为参数而不是 blob。尝试重构代码如下所示:

// 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 reviewRef.getDownloadURL();

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

【讨论】:

  • 感谢您在美国西海岸创业。很高兴你进入 YC?
  • 将 videoRef 更改为 reviewRef
猜你喜欢
  • 2020-04-02
  • 2018-07-18
  • 2018-10-02
  • 1970-01-01
  • 2020-07-19
  • 2018-08-27
  • 2021-04-06
  • 2020-05-13
  • 2017-02-25
相关资源
最近更新 更多