Datastore.prototype.keyToLegacyUrlSafe(key: entity.Key,locationPrefix?: string,): Promise<string>
Helper to create a URL safe key.
This is intended to work with the "legacy" representation of a datastore "Key" used within Google App Engine (a so-called "Reference"). The returned string can be used as the "urlsafe" The base64 encoded values will have padding removed.
Example 1
Example 1
const {Datastore} = require('@google-cloud/datastore'); const datastore = new Datastore(); const key = datastore.key(['Company', 'Google']); datastore.keyToLegacyUrlSafe(key, (err, urlSafeKey) => { if (err) { // Error handling omitted. } console.log(urlSafeKey); }); //- // Create a complete URL-safe key using a location prefix. //- const locationPrefix = 's~'; datastore.keyToLegacyUrlSafe(key, locationPrefix, (err, urlSafeKey) => { if (err) { // Error handling omitted. } console.log(urlSafeKey); }); //- // If the callback is omitted, we'll return a Promise. //- datastore.keyToLegacyUrlSafe(key).then((data) => { const urlSafeKey = data[0]; console.log(urlSafeKey); });