Google Cloud Node.js Client
Node.js client for Google Cloud Storage service. Intended for use with Meteor.
This client supports only Google Cloud Storage! If you need more APIs for the Google Cloud Platform, please check out the offical gcloud project
If you need support for other Google APIs, check out the Google Node.js API Client library.
Quick Start
$ npm install --save google-cloud-storage-standalone
Authentication
With google-cloud-storage-standalone
it's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Google Cloud services.
You need a Google Developers service account. To create a service account:
- Visit the Google Developers Console.
- Create a new project or click on an existing project.
- Navigate to APIs & auth > APIs section and turn on the following APIs (you may need to enable billing in order to use these services):
- Google Cloud Datastore API
- Google Cloud Storage
- Google Cloud Storage JSON API
- Navigate to APIs & auth > Credentials and then:
- If you want to use a new service account, click on Create new Client ID and select Service account. After the account is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests.
- If you want to generate a new key for an existing service account, click on Generate new JSON key and download the JSON key file.
var projectId = process.env.GCLOUD_PROJECT;
var gcloud = require('gcloud')({
projectId: projectId,
keyFilename: '/path/to/keyfile.json'
});
Google Cloud Storage
If you need more information for Google Cloud Storage, please refer to following docs
Preview
var fs = require('fs');
var gcloud = require('gcloud');
var gcs = gcloud.storage({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
gcs.createBucket('my-new-bucket', function(err, bucket) {
if (!err) {
}
});
var bucket = gcs.bucket('my-existing-bucket');
bucket.upload('/photos/zoo/zebra.jpg', function(err, file) {
if (!err) {
}
});
bucket.file('giraffe.jpg').download({
destination: '/photos/zoo/giraffe.jpg'
}, function(err) {});
var remoteReadStream = bucket.file('giraffe.jpg').createReadStream();
var localWriteStream = fs.createWriteStream('/photos/zoo/giraffe.jpg');
remoteReadStream.pipe(localWriteStream);
var localReadStream = fs.createReadStream('/photos/zoo/zebra.jpg');
var remoteWriteStream = bucket.file('zebra.jpg').createWriteStream();
localReadStream.pipe(remoteWriteStream);
Contributing
Contributions to this library are always welcome and highly encouraged.
See CONTRIBUTING for more information on how to get started.
License
Apache 2.0 - See COPYING for more information.