Class Storage_2 (7.16.0)

Inheritance

Service >Storage_2

Package

@google-cloud/storage

Constructors

(constructor)(options)

constructor(options?:StorageOptions);

Constructs the Storage client.

Parameter
NameDescription
optionsStorageOptions

Configuration options.

Examples

Create a client that uses Application Default Credentials (ADC)

const{Storage}=require('@google-cloud/storage');conststorage=newStorage();

Create a client with explicit credentials

conststorage=newStorage({projectId:'your-project-id',keyFilename:'/path/to/keyfile.json'});

Create a client with credentials passed by value as a JavaScript object

conststorage=newStorage({projectId:'your-project-id',credentials:{type:'service_account',project_id:'xxxxxxx',private_key_id:'xxxx',private_key:'-----BEGIN PRIVATE KEY-----xxxxxxx\n-----END PRIVATE KEY-----\n',client_email:'xxxx',client_id:'xxx',auth_uri:'https://accounts.google.com/o/oauth2/auth',token_uri:'https://oauth2.googleapis.com/token',auth_provider_x509_cert_url:'https://www.googleapis.com/oauth2/v1/certs',client_x509_cert_url:'xxx',}});

Create a client with credentials passed by loading a JSON file directly from disk

conststorage=newStorage({projectId:'your-project-id',credentials:require('/path/to-keyfile.json')});

Create a client with anAuthClient (e.g.DownscopedClient)

const{DownscopedClient}=require('google-auth-library');constauthClient=newDownscopedClient({...});conststorage=newStorage({authClient});

Additional samples: - https://github.com/googleapis/google-auth-library-nodejs#sample-usage-1 -https://github.com/googleapis/google-auth-library-nodejs/blob/main/samples/downscopedclient.js

Properties

acl

acl:typeofStorage.acl;

Reference to .

Storage#acl

acl

staticacl:{OWNER_ROLE:string;READER_ROLE:string;WRITER_ROLE:string;};

Bucket

staticBucket:typeofBucket;

Bucket class.

Storage.Bucket

Channel

staticChannel:typeofChannel;

Channel class.

Storage.Channel

crc32cGenerator

crc32cGenerator:CRC32CValidatorGenerator;

File

staticFile:typeofFile;

class.

Storage.File

HmacKey

staticHmacKey:typeofHmacKey;

HmacKey class.

Storage.HmacKey

retryOptions

retryOptions:RetryOptions;

Methods

bucket(name, options)

bucket(name:string,options?:BucketOptions):Bucket;

Get a reference to a Cloud Storage bucket.

Parameters
NameDescription
namestring

Name of the bucket.

optionsBucketOptions

Configuration object.

Returns
TypeDescription
Bucket

{Bucket}

Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();constalbums=storage.bucket('albums');constphotos=storage.bucket('photos');

channel(id, resourceId)

channel(id:string,resourceId:string):Channel;

Reference a channel to receive notifications about changes to your bucket.

Parameters
NameDescription
idstring

The ID of the channel.

resourceIdstring

The resource ID of the channel.

Returns
TypeDescription
Channel

{Channel}

Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();constchannel=storage.channel('id','resource-id');

createBucket(name, metadata)

createBucket(name:string,metadata?:CreateBucketRequest):Promise<CreateBucketResponse>;
Parameters
NameDescription
namestring
metadataCreateBucketRequest
Returns
TypeDescription
Promise<CreateBucketResponse>

createBucket(name, callback)

createBucket(name:string,callback:BucketCallback):void;
Parameters
NameDescription
namestring
callbackBucketCallback
Returns
TypeDescription
void

createBucket(name, metadata, callback)

createBucket(name:string,metadata:CreateBucketRequest,callback:BucketCallback):void;
Parameters
NameDescription
namestring
metadataCreateBucketRequest
callbackBucketCallback
Returns
TypeDescription
void

createBucket(name, metadata, callback)

createBucket(name:string,metadata:CreateBucketRequest,callback:BucketCallback):void;
Parameters
NameDescription
namestring
metadataCreateBucketRequest
callbackBucketCallback
Returns
TypeDescription
void

createHmacKey(serviceAccountEmail, options)

createHmacKey(serviceAccountEmail:string,options?:CreateHmacKeyOptions):Promise<CreateHmacKeyResponse>;
Parameters
NameDescription
serviceAccountEmailstring
optionsCreateHmacKeyOptions
Returns
TypeDescription
Promise<CreateHmacKeyResponse>

createHmacKey(serviceAccountEmail, callback)

createHmacKey(serviceAccountEmail:string,callback:CreateHmacKeyCallback):void;
Parameters
NameDescription
serviceAccountEmailstring
callbackCreateHmacKeyCallback
Returns
TypeDescription
void

createHmacKey(serviceAccountEmail, options, callback)

createHmacKey(serviceAccountEmail:string,options:CreateHmacKeyOptions,callback:CreateHmacKeyCallback):void;
Parameters
NameDescription
serviceAccountEmailstring
optionsCreateHmacKeyOptions
callbackCreateHmacKeyCallback
Returns
TypeDescription
void

getBuckets(options)

getBuckets(options?:GetBucketsRequest):Promise<GetBucketsResponse>;
Parameter
NameDescription
optionsGetBucketsRequest
Returns
TypeDescription
Promise<GetBucketsResponse>

getBuckets(options, callback)

getBuckets(options:GetBucketsRequest,callback:GetBucketsCallback):void;
Parameters
NameDescription
optionsGetBucketsRequest
callbackGetBucketsCallback
Returns
TypeDescription
void

getBuckets(callback)

getBuckets(callback:GetBucketsCallback):void;
Parameter
NameDescription
callbackGetBucketsCallback
Returns
TypeDescription
void

getBucketsStream()

getBucketsStream():Readable;
Returns
TypeDescription
Readable

getHmacKeys(options)

getHmacKeys(options?:GetHmacKeysOptions):Promise<GetHmacKeysResponse>;

Retrieves a list of HMAC keys matching the criteria.

The authenticated user must have storage.hmacKeys.list permission for the project in which the key exists.

Parameter
NameDescription
optionsGetHmacKeysOptions

Configuration options.

Returns
TypeDescription
Promise<GetHmacKeysResponse>
Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();storage.getHmacKeys(function(err,hmacKeys){if(!err){// hmacKeys is an array of HmacKey objects.}});//-// To control how many API requests are made and page through the results// manually, set `autoPaginate` to `false`.//-constcallback=function(err,hmacKeys,nextQuery,apiResponse){if(nextQuery){// More results exist.storage.getHmacKeys(nextQuery,callback);}// The `metadata` property is populated for you with the metadata at the// time of fetching.hmacKeys[0].metadata;};storage.getHmacKeys({autoPaginate:false},callback);//-// If the callback is omitted, we'll return a Promise.//-storage.getHmacKeys().then(function(data){consthmacKeys=data[0];});

getHmacKeys(callback)

getHmacKeys(callback:GetHmacKeysCallback):void;
Parameter
NameDescription
callbackGetHmacKeysCallback
Returns
TypeDescription
void

getHmacKeys(options, callback)

getHmacKeys(options:GetHmacKeysOptions,callback:GetHmacKeysCallback):void;
Parameters
NameDescription
optionsGetHmacKeysOptions
callbackGetHmacKeysCallback
Returns
TypeDescription
void

getHmacKeysStream()

getHmacKeysStream():Readable;
Returns
TypeDescription
Readable

getServiceAccount(options)

getServiceAccount(options?:GetServiceAccountOptions):Promise<GetServiceAccountResponse>;
Parameter
NameDescription
optionsGetServiceAccountOptions
Returns
TypeDescription
Promise<GetServiceAccountResponse>

getServiceAccount(options)

getServiceAccount(options?:GetServiceAccountOptions):Promise<GetServiceAccountResponse>;
Parameter
NameDescription
optionsGetServiceAccountOptions
Returns
TypeDescription
Promise<GetServiceAccountResponse>

getServiceAccount(options, callback)

getServiceAccount(options:GetServiceAccountOptions,callback:GetServiceAccountCallback):void;
Parameters
NameDescription
optionsGetServiceAccountOptions
callbackGetServiceAccountCallback
Returns
TypeDescription
void

getServiceAccount(callback)

getServiceAccount(callback:GetServiceAccountCallback):void;
Parameter
NameDescription
callbackGetServiceAccountCallback
Returns
TypeDescription
void

hmacKey(accessId, options)

hmacKey(accessId:string,options?:HmacKeyOptions):HmacKey;

Get a reference to an HmacKey object. Note: this does not fetch the HMAC key's metadata. Use HmacKey#get() to retrieve and populate the metadata.

To get a reference to an HMAC key that's not created for a service account in the same project used to instantiate the Storage client, supply the project's ID asprojectId in theoptions argument.

Parameters
NameDescription
accessIdstring

The HMAC key's access ID.

optionsHmacKeyOptions

HmacKey constructor options.

Returns
TypeDescription
HmacKey

{HmacKey}

Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();consthmacKey=storage.hmacKey('ACCESS_ID');

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.