method Datastore.prototype.keyToLegacyUrlSafe
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.

Examples

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

Parameters

key: entity.Key

Entity key object.

optional
locationPrefix: string

Optional . The location prefix of an App Engine project ID. Often this value is 's~', but may also be 'e~', or other location prefixes currently unknown.

Return Type

Promise<string>
Datastore.prototype.keyToLegacyUrlSafe(
key: entity.Key,
callback: KeyToLegacyUrlSafeCallback,
): void

Parameters

key: entity.Key
callback: KeyToLegacyUrlSafeCallback

Return Type

void
Datastore.prototype.keyToLegacyUrlSafe(
key: entity.Key,
locationPrefix: string,
callback: KeyToLegacyUrlSafeCallback,
): void

Parameters

key: entity.Key
locationPrefix: string
callback: KeyToLegacyUrlSafeCallback

Return Type

void