Skip to content

Allow setting of custom metadata #368

Description

@ggoodman

I understand from the documents for cloud storage that it is possible to set custom metadata with the x-goog-meta- prefix as specified here: https://cloud.google.com/storage/docs/reference-headers#xgoogmeta

I've tried to take this approach to set custom metadata on objects created using gcloud-node as follows:

    var stream = file.createWriteStream({
      metadata: {
        'x-goog-meta-entry-type': entry.type,
      }
    });

    stream.once("finish", resolve);
    stream.once("error", reject);
    stream.end(buffer);

However, no objects created using that approach have the custom metadata reflected when requested via file.getMetadata() nor when viewed via the online storage browser.

How can one set custom metadata using gcloud-node?

Activity

  1. added this to the Storage Stable milestone on Feb 2, 2015
  2. stephenplusplus commented on Feb 2, 2015

    @stephenplusplus
    Contributor

    Thanks for catching this! I'm talking to myself about a good solution over in #373 - feel free to chime in :)

  3. ryanseys commented on Feb 2, 2015

    @ryanseys
    Contributor

    Hey @ggoodman nice issue! This raises an entirely different question as well and that is: "Do we have a way to specify custom headers?" I'm going to guess no. But I think that's okay, because doing that is beyond the scope of this library. That being said, I think we do support custom metadata already although it's poorly documented. What you need to do is a set a metadata object within your original metadata object, like so:

    fs.createReadStream('/my/local/file.png')
      .pipe(image.createWriteStream({
        metadata: { 
          contentType: 'image/jpeg',
          metadata: {
            customProperty: 'my cool photo'
          }
        }
      }))
      .on('error', function(err) {});
  4. dhermes commented on Feb 2, 2015

    @dhermes
    Contributor

    @ggoodman

    Notice the docs you linked to are under the hierarchy

    Cloud Storage API >XML API > API Reference > Headers and Query Parameters
    

    So this header (I'm fairly certain) only applies to the XML API, not the JSON API.

  5. ryanseys commented on Feb 2, 2015

    @ryanseys
    Contributor

    @dhermes Good catch, I did not notice this either.

  6. ggoodman commented on Feb 2, 2015

    @ggoodman
    Author

    Hi @dhermes good catch. I guess I wasn't able to identify the correct api that backs this project. Perhaps that is an issue itself. I consider myself a passable code / documentation spelunker and wasn't able to track this down.

    My path there was:

    1. Have a need for custom metadata
    2. Identify that the underlying service supports custom metadata
    3. Search left and right for anything cloud storage and custom metadata

    I think that a simple fix would be to clarify that custom metadata is settable via the metadata of the metadata in the documents. At the same time, it would be nice to describe how said custom metadata will be returned via the getMetadata() call.

    Thanks for taking a look at this so quickly, @dhermes and @ryanseys.

  7. ggoodman commented on Feb 2, 2015

    @ggoodman
    Author

    I have not tried @ryanseys recommendation, but if true, would obviate this issue and I'd be happy to close. What do you think?

  8. stephenplusplus commented on Feb 4, 2015

    @stephenplusplus
    Contributor

    Yeah, I'll close this for now as metadata.metadata should work fine. If you try and that's not correct, just open it back up.

  9. 32 remaining items

  10. added a commit that references this issue on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🚨This issue needs some love.api: storageIssues related to the Cloud Storage API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions