【问题标题】:Google Cloud Storage node client ResumableUploadError谷歌云存储节点客户端 ResumableUploadError
【发布时间】:2019-05-08 15:19:56
【问题描述】:

我们有一个在 GCP 和 Kubernetes 服务中运行的应用。后端位于运行节点/高山基础映像的容器内。我们尝试使用 Google Cloud Storage (@google-cloud/storage": "~2.0.3") 的 nodejs 客户端库将文件更新到我们的存储桶,就像在 github 存储库示例中一样:

storage.bucket(bucketName)
                .upload(path.join(sourcePath, filename),
                    {
                        'gzip': true,
                        'metadata': {
                            'cacheControl': 'public, max-age=31536000',
                        },
                    }, (err) => {
                        if (err) {
                            return reject(err);
                        }

                        return resolve(true);
                    });
        });

它适用于小于 5Mb 的文件,但是当我得到更大的文件时,我得到一个错误:

{"name":"ResumableUploadError"}

谷歌搜索后,我看到客户端自动切换到可恢复上传。不幸的是,我找不到任何关于如何使用节点客户端管理这种特殊情况的示例。我们希望最多允许 50Mb,所以现在有点担心。

【问题讨论】:

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


    【解决方案1】:

    好的,您知道问题是因为我的容器运行的是节点/高山映像。 alpine 发行版被剥离到最低限度,因此 google-cloud/storageConfigstore 库没有使用 ~/.config 文件夹/strong> 节点库。我不得不进入 repo 检查代码并在file.ts 中看到注释一旦我在容器中添加了文件夹(通过在 Dockerfile 中添加 RUN mkdir ~/.config),一切都开始按预期工作。

    【讨论】:

      【解决方案2】:

      您也可以在传入的选项中设置resumable: false。因此完整的代码如下所示:

      storage.bucket(bucketName)
                      .upload(path.join(sourcePath, filename),
                          {
                              'resumable': false,
                              'gzip': true, 
                              'metadata': {
                                  'cacheControl': 'public, max-age=31536000',
                              },
                          }, (err) => {
                              if (err) {
                                  return reject(err);
                              }
      
                              return resolve(true);
                          });
              });
      

      【讨论】:

        【解决方案3】:

        如果您仍然希望进行可恢复上传并且您不想在 Dockerfile 中创建额外的定制目录,这里是另一种解决方案。

        可恢复上传需要可访问的可写目录。根据操作系统和您安装@google-cloud/storage 的方式,默认配置路径可能会发生变化。为确保这始终有效,无需在 Dockerfile 中创建特定目录,您可以将 configPath 指定为可写文件。

        这是您可以执行的操作的示例。确保将 configPath 指向一个 file 而不是现有的 directory(否则你会得到Error: EISDIR: illegal operation on a directory, read)

        gcsBucket.upload(
          `${filePath}`,
          {
            destination: `${filePath}`,
            configPath: `${writableDirectory}/.config`,
            resumable: true
          }
        )
        

        【讨论】:

          猜你喜欢
          • 2016-03-21
          • 1970-01-01
          • 1970-01-01
          • 2017-11-23
          • 1970-01-01
          • 2018-03-26
          • 1970-01-01
          • 1970-01-01
          • 2014-05-04
          相关资源
          最近更新 更多