【问题标题】:Node.js failed to upload image file to firebase from the serverNode.js 无法将图像文件从服务器上传到 firebase
【发布时间】:2020-08-29 13:24:36
【问题描述】:

我正在使用 firebase-admin 包在节点 js 中的服务器端上传图像:

const upload = await bucket.upload('myimage.png', {
    destination: "myimage.png",
    metadata: {
        contentType: 'image/png'
    }
});

它不起作用,文件上传成功,但即使内容类型是我在 matadata 中设置的,firebase 存储也无法将其读取为图像。

当我手动上传同一张图片时,它会将其读取为 png 图片。

请帮忙 :) 谢谢

【问题讨论】:

  • "firebase 存储无法将其作为图像读取" => 您如何尝试读取它?通过 Firebase 控制台?
  • 在firebase存储页面中无法显示

标签: node.js firebase google-cloud-storage


【解决方案1】:

Firebase 控制台使用图片的下载 URL 来显示它们。当您通过 Admin SDK 上传图片时,它使用的是 Node.js SDK for Cloud Storage,并且此 SDK 不会生成下载 URL,因此 Firebase 控制台无法显示以这种方式上传的图片。

请参阅此issues in the Github repo of the Admin SDK 了解更多信息。它还包含一个workaround/solution。我自己没有尝试过,但看起来很有希望。

另一个解决方法似乎在这个答案中:Cloud Functions: Resized images not loading

【讨论】:

    猜你喜欢
    • 2021-03-25
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    相关资源
    最近更新 更多