首页 > 解决方案 > @google-cloud/storage 使用 generateSignedPostPolicyV4 出错

问题描述

我正在关注这个例子: https ://github.com/googleapis/nodejs-storage/blob/master/samples/generateV4SignedPolicy.js

我唯一的改变是:

const bucketName = "gs://my-bucket.appspot.com/";
const filename = "test.jpg";

const { Storage } = require("@google-cloud/storage");

const storage = new Storage({
  projectId: require("./key.json").project_id,
  credentials: require("./key.json"),
});

然后我将输出导出到一个 HTML 文件来测试它:

node index.js > index.html

但是当我提交文件时,我收到:

<Error>
   <Code>InvalidPolicyDocument</Code>
   <Message>
      The content of the form does not meet the conditions specified in the policy document.
   </Message>
   <Details>
      Policy did not reference these fields: bucket submit
   </Details>
</Error>

这是代码示例中的错误吗?

我需要任何配置/权限吗?

标签: google-cloud-storage

解决方案


我最后一次工作是在 5 月 11 日星期一。我认为他们更新了 API 以不自动将存储桶添加到字段列表中。修复很简单,只需在创建时将存储桶添加到字段列表中。

...
const options = {
  expires,
  fields: {
    'x-goog-meta-test': 'data',
    'bucket': 'my-bucket'
  },
};
...

编辑:找到引用此重大更改的 PR。https://github.com/googleapis/conformance-tests/pull/31。不久之后,@google-cloud/storage 模块可能会更新。


推荐阅读