Search code examples
node.jsgoogle-cloud-storagegcloud-node

Can you update metadata with gcloud-node


I'm using gcloud-node to store files on Google Cloud Storage. I would like to update metadata, like the timestamp ala touch. Is that possible?


Solution

  • You can pass the metadata to bucket.write as in:

    data = {
      data: 'Hello World',
      metadata: {
        // ...
      }
    };
    bucket.write('HelloMessageFile', data, function(err, fileObject) {});
    

    If you want to update the metadata for an existing file, just pass the metadata inside data:

    data = {
      metadata: {
        // ...
      }
    };
    bucket.write('HelloMessageFile', data, function(err, fileObject) {});