首页 > 解决方案 > 使用 file.save() 将图像上传到 Google Cloud Storage。一切似乎都成功,但图像不起作用

问题描述

我正在尝试将图像上传到 Google Cloud Storage 以在网站上使用。我正在从 apiflash 截屏并接收图像数据。

使用图像数据,然后我尝试使用 file.save() 将其保存到 Google Cloud

除了图像未显示之外,一切都在进行中。

这是 Gcloud 存储仪表板中的图像。

它正在抛出的错误消息

错误信息

这是上传的代码。我错过了什么吗?它成功并且上传工作,只是没有图像。返回的图像是 jpeg 类型,我尝试过使用 .jpg 并且还接收到 png,但这会产生相同的错误。

响应正文只是图像数据,没有别的......很多......

0\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05(\x00\x01J\x00\x00R�\x00\x14�\x00\x05+��"

        request(options, function (error, response) {
          if (error) throw new Error(error);
          const content = response.body;
          const file = bucket.file(`${gameid}.jpeg`);
          file.save(
            content,
            {
              resumable: false,
              public: true,
              contentType: response.headers['content-type'],
            },
            (err) => {
              if (!err) {
                console.log('success');
              } else {
                console.log('ERROR', err);
              }
            }
          );
        });

任何意见,将不胜感激。

谢谢

标签: javascriptnode.jsimagegoogle-cloud-storage

解决方案


推荐阅读