首页 > 解决方案 > Firebase 在尝试上传文件时给出“ERROR error [object Object]”

问题描述

我正在尝试将图像上传到 Firebase 存储,但它以高度描述性的ERROR Error: "[object Object]".

我的文件是这样读入的:

previewImage(image) {
    let reader = new FileReader();
    reader.readAsDataURL(image.files[0])
    reader.onload = (event) => {
      this.image = event.target.result;
    }
  }

然后被发送到这样的服务:

    this.db.addToBucket(`images/profiles/${this.user.id}.png`, this.image)

在服务中,我尝试像这样上传它:

addToBucket(path, file) {
    console.log(path);
    this.storage.ref(path).put(file).then(function(snapshot) {
      console.log(snapshot);
    })
  }

所以,参考应该像images/profiles/1.png. 该文件应该是一个 base64 对象,这似乎是文档要求的。我真的不知道整个过程是如何工作的,所以我还包括了 base64 图像本身(整个事情),尽管我认为只有 start 是必要的。您可以在此处的 pastebin 中找到它。

我有一种明显的感觉,这只是对 API 的简单滥用,没有什么比这更大的了,但我真的不知道是什么原因造成的。作为参考,当我记录路径时,它会显示images/profiles/12968216.png为适合我的需要,但该位置的存储中尚不存在任何内容。我创建了文件夹,但还没有图像。

标签: javascriptfirebasefile-uploadblobfirebase-storage

解决方案


推荐阅读