How to use the gcloud.storage function in gcloud

To help you get started, we’ve selected a few gcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jasonpolites / gcf-recipes / gcs / index.js View on Github external
if (!bucketName) {
      context.failure(
        'Bucket not provided. Make sure you have a \'bucket\' property in ' +
        'your request');
      return;
    }
    if (!fileName) {
      context.failure(
        'Filename not provided. Make sure you have a \'file\' property in ' +
        'your request');
      return;
    }

    // Create a gcs client.
    var gcs = gcloud.storage({
      // We're using the API from the same project as the Cloud Function.
      projectId: process.env.GCP_PROJECT,
    });

    var bucket = gcs.bucket(bucketName);
    var file = bucket.file(fileName);
    var count = 0;

    // Use the readLine module to read the stream line-by line.
    var lineReader = readline.createInterface({
      input: file.createReadStream(),
    });

    lineReader.on('line', function(line) {
      count += line.trim().split(/\s+/).length;
    });
github jasonpolites / gcf-recipes / bigquery / app / index.js View on Github external
var _getStorageClient = function() {
  if (storage === null) {
    storage = gcloud.storage({
      // We're using the API from the same project as the Cloud Function
      projectId: process.env.GCP_PROJECT,
    });
  }
  return storage;
};
github jasonpolites / gcf-recipes / worker_pubsub / index.js View on Github external
'master': function(context, data) {

    // Create a gcs client
    var gcs = gcloud.storage({
      // We're using the API from the same project as the Cloud Function.
      projectId: process.env.GCP_PROJECT,
    });

    // Create a pubsub client to publish the work and read the results of the workers.
    var pubsub = gcloud.pubsub({
      // We're using the API from the same project as the Cloud Function.
      projectId: process.env.GCP_PROJECT,
    });

    // Get the bucket containing our source file
    var bucket = gcs.bucket(data['bucket']);

    // The topic we are going to publish to
    var inTopic = pubsub.topic(data['in-topic']);
github jasonpolites / gcf-recipes / worker_http / index.js View on Github external
var _master = function(context, data) {

  // Create a gcs client
  var gcs = gcloud.storage({
    // We're using the API from the same project as the Cloud Function.
    projectId: process.env.GCP_PROJECT,
  });

  // Get the location (url) of the map function
  var fnUrl = data['workerFunctionUrl'];

  // Get the bucket containing our source file
  var bucket = gcs.bucket(data['bucket']);

  // Load the master file using the stream API
  logger.log(
    'Opening file [' + data['file'] + '] and creating a read stream...');
  var inStream = bucket.file(data['file']).createReadStream()
    .on('error', function(err) {
      context.failure('Error reading file stream for ' + data['file'] +
github hakobera / mongobq / lib / gcp.js View on Github external
GCSFile.prototype.storage = function () {
  return gcloud.storage(this.projectSettings);
};
github parse-community / parse-server / src / Adapters / Files / GCSAdapter.js View on Github external
keyFilename = requiredOrFromEnvironment('GCP_KEYFILE_PATH', 'keyfile path'),
    bucket = requiredOrFromEnvironment('GCS_BUCKET', 'bucket name'),
    { bucketPrefix = fromEnvironmentOrDefault('GCS_BUCKET_PREFIX', ''),
      directAccess = fromEnvironmentOrDefault('GCS_DIRECT_ACCESS', false) } = {}) {
    super();

    this._bucket = bucket;
    this._bucketPrefix = bucketPrefix;
    this._directAccess = directAccess;

    let options = {
      projectId: projectId,
      keyFilename: keyFilename
    };

    this._gcsClient = new storage(options);
  }

gcloud

Google Cloud APIs Client Library for Node.js

Apache-2.0
Latest version published 8 years ago

Package Health Score

63 / 100
Full package analysis