@google-cloud/storage

Cloud Storage Client Library for Node.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@google-cloud/storage
878247.10.119 hours ago8 years agoMinified + gzip package size for @google-cloud/storage in KB

Readme

Google Cloud Platform logorelease level npm version
Node.js idiomatic client for Cloud Storageproduct-docs.

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 Explainedexplained.
Table of contents:
Before you begin Installing the client library Using the client library

Quickstart

Before you begin

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

Installing the client library

npm install @google-cloud/storage

Using the client library

// 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.
| Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | | Add Bucket Conditional Binding | source code | !Open in Cloud Shellshellimg | | Add Bucket Default Owner Acl | source code | !Open in Cloud Shellshellimg | | Add Bucket Iam Member | source code | !Open in Cloud Shellshellimg | | Storage Add Bucket Label. | source code | !Open in Cloud Shellshellimg | | Add Bucket Owner Acl | source code | !Open in Cloud Shellshellimg | | Bucket Website Configuration. | source code | !Open in Cloud Shellshellimg | | Add File Owner Acl | source code | !Open in Cloud Shellshellimg | | Storage Get Bucket Metadata. | source code | !Open in Cloud Shellshellimg | | Change Bucket's Default Storage Class. | source code | !Open in Cloud Shellshellimg | | Storage File Convert CSEK to CMEK. | source code | !Open in Cloud Shellshellimg | | Storage Combine files. | source code | !Open in Cloud Shellshellimg | | Storage Configure Bucket Cors. | source code | !Open in Cloud Shellshellimg | | Configure Retries | source code | !Open in Cloud Shellshellimg | | Copy File | source code | !Open in Cloud Shellshellimg | | Copy Old Version Of File. | source code | !Open in Cloud Shellshellimg | | Create a Dual-Region Bucket | source code | !Open in Cloud Shellshellimg | | Create a Bucket with object retention enabled. | source code | !Open in Cloud Shellshellimg | | Create Bucket With Storage Class and Location. | source code | !Open in Cloud Shellshellimg | | Create Bucket With Turbo Replication | source code | !Open in Cloud Shellshellimg | | Create New Bucket | source code | !Open in Cloud Shellshellimg | | Create Notification | source code | !Open in Cloud Shellshellimg | | Delete Bucket | source code | !Open in Cloud Shellshellimg | | Delete File | source code | !Open in Cloud Shellshellimg | | Delete Notification | source code | !Open in Cloud Shellshellimg | | Delete Old Version Of File. | source code | !Open in Cloud Shellshellimg | | Disable Bucket Lifecycle Management | source code | !Open in Cloud Shellshellimg | | Storage Disable Bucket Versioning. | source code | !Open in Cloud Shellshellimg | | Disable Default Event Based Hold | source code | !Open in Cloud Shellshellimg | | Disable Requester Pays | source code | !Open in Cloud Shellshellimg | | Disable Uniform Bucket Level Access | source code | !Open in Cloud Shellshellimg | | Download Byte Range | source code | !Open in Cloud Shellshellimg | | Download Encrypted File | source code | !Open in Cloud Shellshellimg | | Download File | source code | !Open in Cloud Shellshellimg | | Download a File in Chunks With Transfer Manager | source code | !Open in Cloud Shellshellimg | | Download File Using Requester Pays | source code | !Open in Cloud Shellshellimg | | Download Folder With Transfer Manager | source code | !Open in Cloud Shellshellimg | | Download Into Memory | source code | !Open in Cloud Shellshellimg | | Download Many Files With Transfer Manager | source code | !Open in Cloud Shellshellimg | | Storage Download Public File. | source code | !Open in Cloud Shellshellimg | | Enable Bucket Lifecycle Management | source code | !Open in Cloud Shellshellimg | | Storage Enable Bucket Versioning. | source code | !Open in Cloud Shellshellimg | | Enable Default Event Based Hold | source code | !Open in Cloud Shellshellimg | | Enable Default KMS Key | source code | !Open in Cloud Shellshellimg | | Enable Requester Pays | source code | !Open in Cloud Shellshellimg | | Enable Uniform Bucket Level Access | source code | !Open in Cloud Shellshellimg | | Change File's Storage Class. | source code | !Open in Cloud Shellshellimg | | Storage Set File Metadata. | source code | !Open in Cloud Shellshellimg | | Generate Encryption Key | source code | !Open in Cloud Shellshellimg | | Generate Signed Url | source code | !Open in Cloud Shellshellimg | | Generate V4 Read Signed Url | source code | !Open in Cloud Shellshellimg | | Generate V4 Signed Policy | source code | !Open in Cloud Shellshellimg | | Generate V4 Upload Signed Url | source code | !Open in Cloud Shellshellimg | | Get Autoclass | source code | !Open in Cloud Shellshellimg | | Get Default Event Based Hold | source code | !Open in Cloud Shellshellimg | | Get Metadata | source code | !Open in Cloud Shellshellimg | | Get Metadata Notifications | source code | !Open in Cloud Shellshellimg | | Get Public Access Prevention | source code | !Open in Cloud Shellshellimg | | Get RPO | source code | !Open in Cloud Shellshellimg | | Get Requester Pays Status | source code | !Open in Cloud Shellshellimg | | Get Retention Policy | source code | !Open in Cloud Shellshellimg | | Storage Get Service Account. | source code | !Open in Cloud Shellshellimg | | Get Uniform Bucket Level Access | source code | !Open in Cloud Shellshellimg | | Activate HMAC SA Key. | source code | !Open in Cloud Shellshellimg | | Create HMAC SA Key. | source code | !Open in Cloud Shellshellimg | | Deactivate HMAC SA Key. | source code | !Open in Cloud Shellshellimg | | Delete HMAC SA Key. | source code | !Open in Cloud Shellshellimg | | Get HMAC SA Key Metadata. | source code | !Open in Cloud Shellshellimg | | List HMAC SA Keys Metadata. | source code | !Open in Cloud Shellshellimg | | List Buckets | source code | !Open in Cloud Shellshellimg | | List Files | source code | !Open in Cloud Shellshellimg | | List Files By Prefix | source code | !Open in Cloud Shellshellimg | | List Files Paginate | source code | !Open in Cloud Shellshellimg | | List Files with Old Versions. | source code | !Open in Cloud Shellshellimg | | List Notifications | source code | !Open in Cloud Shellshellimg | | Lock Retention Policy | source code | !Open in Cloud Shellshellimg | | Storage Make Bucket Public. | source code | !Open in Cloud Shellshellimg | | Make Public | source code | !Open in Cloud Shellshellimg | | Move File | source code | !Open in Cloud Shellshellimg | | Print Bucket Acl | source code | !Open in Cloud Shellshellimg | | Print Bucket Acl For User | source code | !Open in Cloud Shellshellimg | | Print File Acl | source code | !Open in Cloud Shellshellimg | | Print File Acl For User | source code | !Open in Cloud Shellshellimg | | Quickstart | source code | !Open in Cloud Shellshellimg | | Release Event Based Hold | source code | !Open in Cloud Shellshellimg | | Release Temporary Hold | source code | !Open in Cloud Shellshellimg | | Remove Bucket Conditional Binding | source code | !Open in Cloud Shellshellimg | | Storage Remove Bucket Cors Configuration. | source code | !Open in Cloud Shellshellimg | | Remove Bucket Default Owner | source code | !Open in Cloud Shellshellimg | | Remove Bucket Iam Member | source code | !Open in Cloud Shellshellimg | | Storage Remove Bucket Label. | source code | !Open in Cloud Shellshellimg | | Remove Bucket Owner Acl | source code | !Open in Cloud Shellshellimg | | Remove Default KMS Key. | source code | !Open in Cloud Shellshellimg | | Remove File Owner Acl | source code | !Open in Cloud Shellshellimg | | Remove Retention Policy | source code | !Open in Cloud Shellshellimg | | Rename File | source code | !Open in Cloud Shellshellimg | | Rotate Encryption Key | source code | !Open in Cloud Shellshellimg | | Set Autoclass | source code | !Open in Cloud Shellshellimg | | Set Client Endpoint | source code | !Open in Cloud Shellshellimg | | Set Event Based Hold | source code | !Open in Cloud Shellshellimg | | Set the object retention policy of a File. | source code | !Open in Cloud Shellshellimg | | Set Public Access Prevention Enforced | source code | !Open in Cloud Shellshellimg | | Set Public Access Prevention Inherited | source code | !Open in Cloud Shellshellimg | | Set RPO Async Turbo | source code | !Open in Cloud Shellshellimg | | Set RPO Default | source code | !Open in Cloud Shellshellimg | | Set Retention Policy | source code | !Open in Cloud Shellshellimg | | Set Temporary Hold | source code | !Open in Cloud Shellshellimg | | Stream File Download | source code | !Open in Cloud Shellshellimg | | Stream File Upload | source code | !Open in Cloud Shellshellimg | | Upload a directory to a bucket. | source code | !Open in Cloud Shellshellimg | | Upload Directory With Transfer Manager | source code | !Open in Cloud Shellshellimg | | Upload Encrypted File | source code | !Open in Cloud Shellshellimg | | Upload File | source code | !Open in Cloud Shellshellimg | | Upload a File in Chunks With Transfer Manager | source code | !Open in Cloud Shellshellimg | | Upload File With Kms Key | source code | !Open in Cloud Shellshellimg | | Upload From Memory | source code | !Open in Cloud Shellshellimg | | Upload Many Files With Transfer Manager | source code | !Open in Cloud Shellshellimg | | Upload Without Authentication | source code | !Open in Cloud Shellshellimg | | Upload Without Authentication Signed Url | source code | !Open in Cloud Shellshellimg | | View Bucket Iam Members | source code | !Open in Cloud Shellshellimg |
The Google Cloud Storage Node.js Client API Referenceclient-docs 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 Stageslaunchstages

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