Back to Google Cloud Node

Google Cloud Storage: Node.js Client

handwritten/storage/README.md

0.57.051.3 KB
Original Source

Google Cloud Storage: Node.js Client

Node.js idiomatic client for Cloud Storage.

Cloud Storage allows world-wide storage and retrieval of any amount of data at any time. You can use Google Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download.

A comprehensive list of changes in each version may be found in the CHANGELOG.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Google Cloud Storage API.
  4. Set up authentication so you can access the API from your local workstation.

Installing the client library

bash
npm install @google-cloud/storage

Using the client library

javascript
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// For more information on ways to initialize Storage, please see
// https://googleapis.dev/nodejs/storage/latest/Storage.html

// Creates a client using Application Default Credentials
const storage = new Storage();

// Creates a client from a Google service account key
// const storage = new Storage({keyFilename: 'key.json'});

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

async function createBucket() {
  // Creates the new bucket
  await storage.createBucket(bucketName);
  console.log(`Bucket ${bucketName} created.`);
}

createBucket().catch(console.error);

Samples

Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.

SampleSource CodeTry it
Add Bucket Conditional Bindingsource code
Add Bucket Default Owner Aclsource code
Add Bucket Iam Membersource code
Storage Add Bucket Label.source code
Add Bucket Owner Aclsource code
Bucket Website Configuration.source code
Add File Owner Aclsource code
Storage Get Bucket Metadata.source code
Change Bucket's Default Storage Class.source code
Storage File Convert CSEK to CMEK.source code
Storage Combine files.source code
Storage Configure Bucket Cors.source code
Configure Retriessource code
Copy Filesource code
Copy Old Version Of File.source code
Create a Dual-Region Bucketsource code
Create a hierarchical namespace enabled bucketsource code
Create a Bucket with object retention enabled.source code
Create Bucket With Storage Class and Location.source code
Create Bucket With Turbo Replicationsource code
Create New Bucketsource code
Create Notificationsource code
Delete Bucketsource code
Delete Filesource code
Delete Notificationsource code
Delete Old Version Of File.source code
Disable Bucket Lifecycle Managementsource code
Storage Disable Bucket Versioning.source code
Disable Default Event Based Holdsource code
Disable Requester Payssource code
Disable Soft Deletesource code
Disable Uniform Bucket Level Accesssource code
Download Byte Rangesource code
Download Encrypted Filesource code
Download Filesource code
Download a File in Chunks With Transfer Managersource code
Download File Using Requester Payssource code
Download Folder With Transfer Managersource code
Download Into Memorysource code
Download Many Files With Transfer Managersource code
Storage Download Public File.source code
Enable Bucket Lifecycle Managementsource code
Storage Enable Bucket Versioning.source code
Enable Default Event Based Holdsource code
Enable Default KMS Keysource code
Enable Requester Payssource code
Enable Uniform Bucket Level Accesssource code
Change File's Storage Class.source code
Storage Set File Metadata.source code
Generate Encryption Keysource code
Generate Signed Urlsource code
Generate V4 Read Signed Urlsource code
Generate V4 Signed Policysource code
Generate V4 Upload Signed Urlsource code
Get Autoclasssource code
Get Default Event Based Holdsource code
Get Metadatasource code
Get Metadata Notificationssource code
Get Public Access Preventionsource code
Get RPOsource code
Get Requester Pays Statussource code
Get Retention Policysource code
Storage Get Service Account.source code
Get Soft Delete Policysource code
Get Soft Deleted Bucketsource code
Get Uniform Bucket Level Accesssource code
Activate HMAC SA Key.source code
Create HMAC SA Key.source code
Deactivate HMAC SA Key.source code
Delete HMAC SA Key.source code
Get HMAC SA Key Metadata.source code
List HMAC SA Keys Metadata.source code
List Bucketssource code
List Buckets Partial Successsource code
List Filessource code
List Files By Prefixsource code
List Files Paginatesource code
List Files with Old Versions.source code
List Notificationssource code
List Soft Deleted Bucketsource code
List Soft Deleted Object Versionssource code
List Soft Deleted Objectssource code
Lock Retention Policysource code
Storage Make Bucket Public.source code
Make Publicsource code
Move Filesource code
Move File Atomicsource code
Print Bucket Aclsource code
Print Bucket Acl For Usersource code
Print File Aclsource code
Print File Acl For Usersource code
Quickstartsource code
Release Event Based Holdsource code
Release Temporary Holdsource code
Remove Bucket Conditional Bindingsource code
Storage Remove Bucket Cors Configuration.source code
Remove Bucket Default Ownersource code
Remove Bucket Iam Membersource code
Storage Remove Bucket Label.source code
Remove Bucket Owner Aclsource code
Remove Default KMS Key.source code
Remove File Owner Aclsource code
Remove Retention Policysource code
Rename Filesource code
Restore Soft Deleted Bucketsource code
Restore Soft Deleted Objectsource code
Rotate Encryption Keysource code
Set Autoclasssource code
Set Client Endpointsource code
Set Event Based Holdsource code
Set the object retention policy of a File.source code
Set Public Access Prevention Enforcedsource code
Set Public Access Prevention Inheritedsource code
Set RPO Async Turbosource code
Set RPO Defaultsource code
Set Retention Policysource code
Set Soft Delete Policysource code
Set Temporary Holdsource code
Stream File Downloadsource code
Stream File Uploadsource code
Upload a directory to a bucket.source code
Upload Directory With Transfer Managersource code
Upload Encrypted Filesource code
Upload Filesource code
Upload a File in Chunks With Transfer Managersource code
Upload File With Kms Keysource code
Upload From Memorysource code
Upload Many Files With Transfer Managersource code
Upload Without Authenticationsource code
Upload Without Authentication Signed Urlsource code
View Bucket Iam Memberssource code

The Google Cloud Storage Node.js Client API Reference documentation also contains samples.

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js. If you are using an end-of-life version of Node.js, we recommend that you update as soon as possible to an actively supported LTS version.

Google's client libraries support legacy versions of Node.js runtimes on a best-efforts basis with the following warnings:

  • Legacy versions are not tested in continuous integration.
  • Some security patches and features cannot be backported.
  • Dependencies cannot be kept up-to-date.

Client libraries targeting some end-of-life versions of Node.js are available, and can be installed through npm dist-tags. The dist-tags follow the naming convention legacy-(version). For example, npm install @google-cloud/storage@legacy-8 installs client libraries for versions compatible with Node.js 8.

Versioning

This library follows Semantic Versioning.

This library is considered to be stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against stable libraries are addressed with the highest priority.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

Please note that this README.md, the samples/README.md, and a variety of configuration files in this repository (including .nycrc and tsconfig.json) are generated from a central template. To edit one of these files, make an edit to its templates in directory.

License

Apache Version 2.0

See LICENSE