Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@google-cloud/storage
Advanced tools
The @google-cloud/storage npm package is a client library for using Google Cloud Storage, which is a service for storing and accessing data on Google's infrastructure. The package allows Node.js developers to interact with Google Cloud Storage in a server-side application.
Uploading files
This feature allows users to upload files to a Google Cloud Storage bucket. The code sample demonstrates how to upload a local file to a specified bucket.
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function uploadFile() {
await storage.bucket('my-bucket').upload('local-file-path', {
destination: 'destination-file-path',
});
console.log('File uploaded.');
}
uploadFile().catch(console.error);
Downloading files
This feature enables users to download files from a Google Cloud Storage bucket. The code sample shows how to download a file from a bucket to the local file system.
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function downloadFile() {
const options = {
destination: 'local-file-path',
};
await storage.bucket('my-bucket').file('remote-file-path').download(options);
console.log('File downloaded.');
}
downloadFile().catch(console.error);
Listing files
This feature provides the ability to list all files in a Google Cloud Storage bucket. The code sample lists the names of all files in a specified bucket.
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function listFiles() {
const [files] = await storage.bucket('my-bucket').getFiles();
files.forEach(file => console.log(file.name));
}
listFiles().catch(console.error);
Deleting files
This feature allows users to delete files from a Google Cloud Storage bucket. The code sample demonstrates how to delete a specific file from a bucket.
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function deleteFile() {
await storage.bucket('my-bucket').file('file-to-delete').delete();
console.log('File deleted.');
}
deleteFile().catch(console.error);
Managing buckets
This feature enables users to manage buckets, including creating and deleting buckets. The code sample shows how to create a new bucket in Google Cloud Storage.
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function createBucket() {
await storage.createBucket('new-bucket');
console.log('Bucket created.');
}
createBucket().catch(console.error);
The aws-sdk package is a client library for Amazon Web Services (AWS), including Amazon S3, which is a similar object storage service to Google Cloud Storage. It provides a wide range of functionalities to interact with various AWS services.
The azure-storage package is a client library for Microsoft Azure Storage. Like Google Cloud Storage, Azure Storage offers blob storage for unstructured data, and this package allows Node.js developers to work with Azure blobs, files, queues, and tables.
The pkgcloud package is a multi-cloud provisioning library for Node.js that abstracts away differences among multiple cloud providers. It supports various cloud services, including storage services like Amazon S3 and Rackspace Cloud Files, and can be used as an alternative to provider-specific packages like @google-cloud/storage.
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:
npm install @google-cloud/storage
// 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 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 | |
Add Bucket Default Owner Acl | source code | |
Add Bucket Iam Member | source code | |
Storage Add Bucket Label. | source code | |
Add Bucket Owner Acl | source code | |
Bucket Website Configuration. | source code | |
Add File Owner Acl | source 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 Retries | source code | |
Copy File | source code | |
Copy Old Version Of File. | source code | |
Create Bucket With Storage Class and Location. | source code | |
Create New Bucket | source code | |
Create Notification | source code | |
Delete Bucket | source code | |
Delete File | source code | |
Delete Notification | source code | |
Delete Old Version Of File. | source code | |
Disable Bucket Lifecycle Management | source code | |
Storage Disable Bucket Versioning. | source code | |
Disable Default Event Based Hold | source code | |
Disable Requester Pays | source code | |
Disable Uniform Bucket Level Access | source code | |
Download Encrypted File | source code | |
Download File | source code | |
Download File Using Requester Pays | source code | |
Storage Download Public File. | source code | |
Enable Bucket Lifecycle Management | source code | |
Storage Enable Bucket Versioning. | source code | |
Enable Default Event Based Hold | source code | |
Enable Default KMS Key | source code | |
Enable Requester Pays | source code | |
Enable Uniform Bucket Level Access | source code | |
Change File's Storage Class. | source code | |
Storage Set File Metadata. | source code | |
Generate Encryption Key | source code | |
Generate Signed Url | source code | |
Generate V4 Read Signed Url | source code | |
Generate V4 Signed Policy | source code | |
Generate V4 Upload Signed Url | source code | |
Get Default Event Based Hold | source code | |
Get Metadata | source code | |
Get Metadata Notifications | source code | |
Get Public Access Prevention | source code | |
Get Requester Pays Status | source code | |
Get Retention Policy | source code | |
Storage Get Service Account. | source code | |
Get Uniform Bucket Level Access | source 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 Buckets | source code | |
List Files | source code | |
List Files By Prefix | source code | |
List Files Paginate | source code | |
List Files with Old Versions. | source code | |
List Notifications | source code | |
Lock Retention Policy | source code | |
Storage Make Bucket Public. | source code | |
Make Public | source code | |
Move File | source code | |
Print Bucket Acl | source code | |
Print Bucket Acl For User | source code | |
Print File Acl | source code | |
Print File Acl For User | source code | |
Quickstart | source code | |
Release Event Based Hold | source code | |
Release Temporary Hold | source code | |
Remove Bucket Conditional Binding | source code | |
Storage Remove Bucket Cors Configuration. | source code | |
Remove Bucket Default Owner | source code | |
Remove Bucket Iam Member | source code | |
Storage Remove Bucket Label. | source code | |
Remove Bucket Owner Acl | source code | |
Remove Default KMS Key. | source code | |
Remove File Owner Acl | source code | |
Remove Retention Policy | source code | |
Rename File | source code | |
Rotate Encryption Key | source code | |
Set Event Based Hold | source code | |
Set Public Access Prevention Enforced | source code | |
Set Public Access Prevention Inherited | source code | |
Set Public Access Prevention Unspecified | source code | |
Set Retention Policy | source code | |
Set Temporary Hold | source code | |
Stream File Download | source code | |
Stream File Upload | source code | |
Upload a directory to a bucket. | source code | |
Upload Encrypted File | source code | |
Upload File | source code | |
Upload File With Kms Key | source code | |
Upload Without Authentication Resumable | source code | |
Upload Without Authentication Signed Url | source code | |
View Bucket Iam Members | source code |
The Google Cloud Storage Node.js Client API Reference documentation also contains samples.
Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js.
Client libraries targeting some end-of-life versions of Node.js are available, and
can be installed via npm dist-tags.
The dist-tags follow the naming convention legacy-(version)
.
Legacy Node.js versions are supported as a best effort:
legacy-8
: install client libraries from this dist-tag for versions
compatible with Node.js 8.This library follows Semantic Versioning.
This library is considered to be General Availability (GA). This means it is 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 GA libraries are addressed with the highest priority.
More Information: Google Cloud Platform Launch Stages
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.
Apache Version 2.0
See LICENSE
FAQs
Cloud Storage Client Library for Node.js
The npm package @google-cloud/storage receives a total of 2,248,879 weekly downloads. As such, @google-cloud/storage popularity was classified as popular.
We found that @google-cloud/storage demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.