Skip to content

need example of how to store unindexed,binary data in datastore #971

Description

@bradabrams

I can't figure out how to store an entity in datastore that has this field... Any idea? Any example would be great

filecontents: {blobValue: filecontents, indexed: false},

Activity

  1. added
    type: questionRequest for information or clarification. Not an issue.
    api: datastoreIssues related to the Datastore API.
    on Nov 30, 2015
  2. jgeewax commented on Nov 30, 2015

    @jgeewax
    Contributor

    I think the answer is to use a Buffer which we'll then notice is a buffer, and set the value as the blob_value in the proto, which shouldn't be indexed... (code is here)

    So the example would look like:

    var gcloud = require('gcloud')({ keyFilename: '/path/to/keyfile.json' });
    var datastore = gcloud.datastore;
    var dataset = datastore.dataset({projectId: 'your-dataset-id'});
    
    var yourBuffer = new Buffer([0x0000, 0x0001, 0x0002]);
    
    /* or you can set this to a file's contents:
    var yourBuffer = fs.readFileSync('/path/to/yourfile');
    */
    
    dataset.save({
      key: dataset.key('YourKind'),
      data: {
        yourBlobProperty: yourBuffer
      }, function(err) {
      if (!err) {
        console.log('Just saved', key.path);
      }
    });
  3. jgeewax commented on Nov 30, 2015

    @jgeewax
    Contributor

    Going to mark this as closed, but feel free to re-open if you think this is wrong.

    If you have an idea for how to improve the docs, feel free to open a PR. The examples for dataset.save have demos of the types we try to support:

    var key = dataset.key('Company');
    
    dataset.save({
      key: key,
      data: {
        name: 'DonutShack', // strings
        rating: gcloud.datastore.int(8), // ints
        worth: gcloud.datastore.double(123456.78), // doubles
        numDonutsServed: 45, // detect number type (int or double)
        founded: new Date('Tue May 12 2015 15:30:00 GMT-0400 (EDT)'), // dates
        isStartup: true, // booleans
        donutEmoji: new Buffer('\uD83C\uDF69'), // buffers
        keywords: [ 'donut', 'coffee', 'yum' ] // lists of objects
      }
    }, function(err) {});
  4. added a commit that references this issue on Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions