1

I'm following this example: https://github.com/googleapis/nodejs-storage/blob/master/samples/generateV4SignedPolicy.js

My only changes were:

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"),
});

Then I exported the output to a HTML file to test it:

node index.js > index.html

But when I submit the file, I receive:

<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>

Is it a bug on the code example?

Do I need any configuration/permissions on my part?

Ralemos
  • 5,571
  • 2
  • 9
  • 18
felipepastorelima
  • 947
  • 1
  • 10
  • 23
  • It can be possible that the `gs://` in the bucket name is not required, since it the on the example you share it states that `'Name of a bucket, e.g. my-bucket'` try that out and let me know if it works. – Ralemos May 11 '20 at 15:16
  • @ralemos same issue =/ – felipepastorelima May 11 '20 at 18:47
  • 1
    Are there any fields named `bucket submit`? The error message indicates that there is a field with that name/type, which is weird as it would have be either bucket or submit. – Ralemos May 12 '20 at 14:26
  • 1
    Same issue here, was working 30ish hours ago and suddenly stopped. – kozan May 12 '20 at 15:29
  • @ralemos Nice catch on the 'submit'. It named the submit button as `name='submit'`. But there is no bucket. – felipepastorelima May 13 '20 at 15:16
  • So did renaming the submit button fixed the issue? – Ralemos May 13 '20 at 16:07
  • Haven't tried this yet, what if you add bucket to the list of fields? ```const options = { expires, fields: { 'x-goog-meta-test': 'data', 'bucket': 'bucket_name' }, }; ``` – kozan May 13 '20 at 16:14
  • 1
    @kozan can you check this, https://stackoverflow.com/questions/74081978/error-creating-gcs-signed-post-policy-for-uploading-file – Husain Batatawala Oct 16 '22 at 14:35

1 Answers1

2

I had this last working on Monday, May 11. I think they updated the API to not add the bucket to the list of fields automatically. Fix is simple, just add the bucket to the list of fields on creation.

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

Edit: Found the PR that references this breaking change. https://github.com/googleapis/conformance-tests/pull/31. There will likely be an update to @google-cloud/storage module sometime soon with the fix.

kozan
  • 94
  • 5