5
votes

I am referring the following code to upload a file into Google Cloud Storage https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/3-binary-data/lib/images.js#L48

I was able to upload successfully, Now i am trying to add metadata to file so i have modified the code as below

  const stream = file.createWriteStream({
    metadata: {
      contentType: req.file.mimetype,
      foo: 'bar'
    }
  });

But the foo=bar metadata is not getting attached to the file in Google Cloud Storage

1

1 Answers

10
votes

If you want to attach metadata to file, then you need to keep that data under metadata. Change your code to the following

const stream = file.createWriteStream({
    metadata: {
      contentType: req.file.mimetype,
      metadata: {
        foo: 'bar'
      }
    }
});