javascript - 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
为适合我的需要,但该位置的存储中尚不存在任何内容。我创建了文件夹,但还没有图像。
解决方案
推荐阅读
- scala - 这是什么意思 - 未应用的方法仅在需要函数类型时才转换为函数
- javascript - Angular 对象不支持 Internet Explorer 的属性或方法“scrollTo”
- angular - Angular CLI 6. 不能在 app.module 的子模块中使用自定义库组件
- java - 反应本机和java之间的WebSocket
- android - Gradle daemon 无法启动 jvm no Xmx1024 或任何其他错误
- solr - Solr:如何在搜索时排除具有负面含义的文本
- c# - C# Unity 项目,运行时冻结
- angular - NativeScript/Angular - 如何在两个应用程序之间共享导入?
- php - 无法使用 PHP 7.1.17 在 Magento 2.1.7 上安装数据迁移工具
- java - 向 TreeMap 添加条目时抛出 NullPointerException