Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bradabrams opened this issue Nov 27, 2015 · 2 comments
Closed

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

bradabrams opened this issue Nov 27, 2015 · 2 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue.

Comments

@bradabrams
Copy link

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},

@jgeewax jgeewax added type: question Request for information or clarification. Not an issue. api: datastore Issues related to the Datastore API. labels Nov 30, 2015
@jgeewax
Copy link
Contributor

jgeewax commented Nov 30, 2015

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);
  }
});

@jgeewax
Copy link
Contributor

jgeewax commented Nov 30, 2015

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) {});

@jgeewax jgeewax closed this as completed Nov 30, 2015
sofisl pushed a commit that referenced this issue Nov 11, 2022
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 470911839

Source-Link: googleapis/googleapis@3527566

Source-Link: googleapis/googleapis-gen@f16a1d2
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjE2YTFkMjI0ZjAwYTYzMGVhNDNkNmE5YTFhMzFmNTY2ZjQ1Y2RlYSJ9

feat: accept google-gax instance as a parameter
Please see the documentation of the client constructor for details.

PiperOrigin-RevId: 470332808

Source-Link: googleapis/googleapis@d4a2367

Source-Link: googleapis/googleapis-gen@e97a1ac
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTk3YTFhYzIwNGVhZDRmZTczNDFmOTFlNzJkYjdjNmFjNjAxNjM0MSJ9

fix: better support for fallback mode
PiperOrigin-RevId: 468790263

Source-Link: googleapis/googleapis@873ab45

Source-Link: googleapis/googleapis-gen@cb6f37a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9

docs: updated some method comments and added an explicit note that DetectIntentRequest's text input is limited by 256 characters
PiperOrigin-RevId: 463362184

Source-Link: googleapis/googleapis@1805fc2

Source-Link: googleapis/googleapis-gen@c47083a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzQ3MDgzYTdiODI5Yzg1ZTM0MjMyNTBmN2NmNDMxZjA3MjM4YWQwNCJ9

docs: added an explicit note that DetectIntentRequest's text input is limited by 256 characters
PiperOrigin-RevId: 463252698

Source-Link: googleapis/googleapis@eeacaab

Source-Link: googleapis/googleapis-gen@da3bfa0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZGEzYmZhMDhiYTc3ZDE0YmE2NmU2ZWVlZTVhZDE1OWVmMzY1ZGYwZiJ9
sofisl pushed a commit that referenced this issue Jan 24, 2023
- fix(deps): use google-gax v3.5.2
- fix: add comma
sofisl pushed a commit that referenced this issue Jan 25, 2023
- fix(deps): use google-gax v3.5.2
- fix: add comma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants