Skip to content

Set initial metadata file on first upload #363

Description

@temka1234

In my project i want to create an empty file in google storage with metadata in one step.
I found this note in gcloud-node/lib/storage/file.js:

...
 * @param {object=} metadata - Metadata to set on the object. This is useful
 *     when you are creating a file for the first time, to prevent making an
 *     extra call to `setMetadata`.
...
function File(bucket, name, metadata) { }

But i cant find any code that use file.metadata parameter in createWriteStream or getWritableStream_.
Also storage.bucket.file(name) method that created new instance of File not contains metadata parameter.

I know, that i can use createWriteStream(metadata). This is the only way?

Activity

  1. stephenplusplus commented on Jan 27, 2015

    @stephenplusplus
    Contributor

    The File constructor taking a metadata argument is a relic of old code, I believe.

    The problem is, creating a File instance (ex: through storage.bucket.file()) shouldn't have any async/api effects. So, it would be confusing if you said...

    var file = myBucket.file('file-name', { metaprop: 'value' })
    file.getMetadata(function(err, metadata) { /* no metaprop here */ })

    ...because the metadata you "set" wasn't actually set.

    Instead, you can explicitly set metadata on a file:

    var file = myBucket.file('file-name')
    file.setMetadata({ metaprop: 'value' }, function(err, metadata) {})

    Or use bucket.upload: http://googlecloudplatform.github.io/gcloud-node/#/docs/v0.12.0/storage/bucket?method=upload

  2. temka1234 commented on Jan 28, 2015

    @temka1234
    Author

    Thanks for the reply!

  3. added this to the Storage Stable milestone on Feb 2, 2015
  4. added a commit that references this issue on Sep 16, 2022
  5. 24 remaining items

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

Metadata

Metadata

Assignees

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