Class Bucket (7.3.2)

Create a Bucket object to interact with a Cloud Storage bucket.

Inheritance

ServiceObject<Bucket, BucketMetadata> > Bucket

Package

@google-cloud/storage

Example


const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('albums');

Constructors

(constructor)(storage, name, options)

constructor(storage: Storage, name: string, options?: BucketOptions);

Constructs a new instance of the Bucket class

Parameters
NameDescription
storage Storage
name string
options BucketOptions

Properties

acl

acl: Acl;

cloudStorageURI

get cloudStorageURI(): URL;

The bucket's Cloud Storage URI (gs://)

Example
ts
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('my-bucket');

// `gs://my-bucket`
const href = bucket.cloudStorageURI.href;

crc32cGenerator

crc32cGenerator: CRC32CValidatorGenerator;

iam

iam: Iam;

instancePreconditionOpts

instancePreconditionOpts?: PreconditionOptions;

name

name: string;

signer

signer?: URLSigner;

storage

storage: Storage;

A reference to the Storage associated with this Bucket instance. Bucket#storage {Storage}

userProject

userProject?: string;

A user project to apply to each request from this bucket. Bucket#userProject {string}

Methods

addLifecycleRule(rule, options)

addLifecycleRule(rule: LifecycleRule | LifecycleRule[], options?: AddLifecycleRuleOptions): Promise<SetBucketMetadataResponse>;
Parameters
NameDescription
rule LifecycleRule | LifecycleRule[]
options AddLifecycleRuleOptions
Returns
TypeDescription
Promise<SetBucketMetadataResponse>

addLifecycleRule(rule, options, callback)

addLifecycleRule(rule: LifecycleRule | LifecycleRule[], options: AddLifecycleRuleOptions, callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
rule LifecycleRule | LifecycleRule[]
options AddLifecycleRuleOptions
callback SetBucketMetadataCallback
Returns
TypeDescription
void

addLifecycleRule(rule, callback)

addLifecycleRule(rule: LifecycleRule | LifecycleRule[], callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
rule LifecycleRule | LifecycleRule[]
callback SetBucketMetadataCallback
Returns
TypeDescription
void

combine(sources, destination, options)

combine(sources: string[] | File[], destination: string | File, options?: CombineOptions): Promise<CombineResponse>;
Parameters
NameDescription
sources string[] | File[]
destination string | File
options CombineOptions
Returns
TypeDescription
Promise<CombineResponse>

combine(sources, destination, options, callback)

combine(sources: string[] | File[], destination: string | File, options: CombineOptions, callback: CombineCallback): void;
Parameters
NameDescription
sources string[] | File[]
destination string | File
options CombineOptions
callback CombineCallback
Returns
TypeDescription
void

combine(sources, destination, callback)

combine(sources: string[] | File[], destination: string | File, callback: CombineCallback): void;
Parameters
NameDescription
sources string[] | File[]
destination string | File
callback CombineCallback
Returns
TypeDescription
void

createChannel(id, config, options)

createChannel(id: string, config: CreateChannelConfig, options?: CreateChannelOptions): Promise<CreateChannelResponse>;
Parameters
NameDescription
id string
config CreateChannelConfig
options CreateChannelOptions
Returns
TypeDescription
Promise<CreateChannelResponse>

createChannel(id, config, callback)

createChannel(id: string, config: CreateChannelConfig, callback: CreateChannelCallback): void;
Parameters
NameDescription
id string
config CreateChannelConfig
callback CreateChannelCallback
Returns
TypeDescription
void

createChannel(id, config, options, callback)

createChannel(id: string, config: CreateChannelConfig, options: CreateChannelOptions, callback: CreateChannelCallback): void;
Parameters
NameDescription
id string
config CreateChannelConfig
options CreateChannelOptions
callback CreateChannelCallback
Returns
TypeDescription
void

createNotification(topic, options)

createNotification(topic: string, options?: CreateNotificationOptions): Promise<CreateNotificationResponse>;
Parameters
NameDescription
topic string
options CreateNotificationOptions
Returns
TypeDescription
Promise<CreateNotificationResponse>

createNotification(topic, options, callback)

createNotification(topic: string, options: CreateNotificationOptions, callback: CreateNotificationCallback): void;
Parameters
NameDescription
topic string
options CreateNotificationOptions
callback CreateNotificationCallback
Returns
TypeDescription
void

createNotification(topic, callback)

createNotification(topic: string, callback: CreateNotificationCallback): void;
Parameters
NameDescription
topic string
callback CreateNotificationCallback
Returns
TypeDescription
void

deleteFiles(query)

deleteFiles(query?: DeleteFilesOptions): Promise<void>;
Parameter
NameDescription
query DeleteFilesOptions
Returns
TypeDescription
Promise<void>

deleteFiles(callback)

deleteFiles(callback: DeleteFilesCallback): void;
Parameter
NameDescription
callback DeleteFilesCallback
Returns
TypeDescription
void

deleteFiles(query, callback)

deleteFiles(query: DeleteFilesOptions, callback: DeleteFilesCallback): void;
Parameters
NameDescription
query DeleteFilesOptions
callback DeleteFilesCallback
Returns
TypeDescription
void

deleteLabels(labels)

deleteLabels(labels?: string | string[]): Promise<DeleteLabelsResponse>;
Parameter
NameDescription
labels string | string[]
Returns
TypeDescription
Promise<DeleteLabelsResponse>

deleteLabels(options)

deleteLabels(options: DeleteLabelsOptions): Promise<DeleteLabelsResponse>;
Parameter
NameDescription
options DeleteLabelsOptions
Returns
TypeDescription
Promise<DeleteLabelsResponse>

deleteLabels(callback)

deleteLabels(callback: DeleteLabelsCallback): void;
Parameter
NameDescription
callback DeleteLabelsCallback
Returns
TypeDescription
void

deleteLabels(labels, options)

deleteLabels(labels: string | string[], options: DeleteLabelsOptions): Promise<DeleteLabelsResponse>;
Parameters
NameDescription
labels string | string[]
options DeleteLabelsOptions
Returns
TypeDescription
Promise<DeleteLabelsResponse>

deleteLabels(labels, callback)

deleteLabels(labels: string | string[], callback: DeleteLabelsCallback): void;
Parameters
NameDescription
labels string | string[]
callback DeleteLabelsCallback
Returns
TypeDescription
void

deleteLabels(labels, options, callback)

deleteLabels(labels: string | string[], options: DeleteLabelsOptions, callback: DeleteLabelsCallback): void;
Parameters
NameDescription
labels string | string[]
options DeleteLabelsOptions
callback DeleteLabelsCallback
Returns
TypeDescription
void

disableAutoRetryConditionallyIdempotent_(coreOpts, methodType, localPreconditionOptions)

disableAutoRetryConditionallyIdempotent_(coreOpts: any, methodType: AvailableServiceObjectMethods, localPreconditionOptions?: PreconditionOptions): void;
Parameters
NameDescription
coreOpts any
methodType AvailableServiceObjectMethods
localPreconditionOptions PreconditionOptions
Returns
TypeDescription
void

disableRequesterPays(options)

disableRequesterPays(options?: DisableRequesterPaysOptions): Promise<DisableRequesterPaysResponse>;
Parameter
NameDescription
options DisableRequesterPaysOptions
Returns
TypeDescription
Promise<DisableRequesterPaysResponse>

disableRequesterPays(callback)

disableRequesterPays(callback: DisableRequesterPaysCallback): void;
Parameter
NameDescription
callback DisableRequesterPaysCallback
Returns
TypeDescription
void

disableRequesterPays(options, callback)

disableRequesterPays(options: DisableRequesterPaysOptions, callback: DisableRequesterPaysCallback): void;
Parameters
NameDescription
options DisableRequesterPaysOptions
callback DisableRequesterPaysCallback
Returns
TypeDescription
void

enableLogging(config)

enableLogging(config: EnableLoggingOptions): Promise<SetBucketMetadataResponse>;
Parameter
NameDescription
config EnableLoggingOptions
Returns
TypeDescription
Promise<SetBucketMetadataResponse>

enableLogging(config, callback)

enableLogging(config: EnableLoggingOptions, callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
config EnableLoggingOptions
callback SetBucketMetadataCallback
Returns
TypeDescription
void

enableRequesterPays(options)

enableRequesterPays(options?: EnableRequesterPaysOptions): Promise<EnableRequesterPaysResponse>;
Parameter
NameDescription
options EnableRequesterPaysOptions
Returns
TypeDescription
Promise<EnableRequesterPaysResponse>

enableRequesterPays(callback)

enableRequesterPays(callback: EnableRequesterPaysCallback): void;
Parameter
NameDescription
callback EnableRequesterPaysCallback
Returns
TypeDescription
void

enableRequesterPays(options, callback)

enableRequesterPays(options: EnableRequesterPaysOptions, callback: EnableRequesterPaysCallback): void;
Parameters
NameDescription
options EnableRequesterPaysOptions
callback EnableRequesterPaysCallback
Returns
TypeDescription
void

file(name, options)

file(name: string, options?: FileOptions): File;

Create a File object. See File to see how to handle the different use cases you may have.

Parameters
NameDescription
name string

The name of the file in this bucket.

options FileOptions

Configuration options.

Returns
TypeDescription
File

{File}

Example

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('albums');
const file = bucket.file('my-existing-file.png');

getFiles(query)

getFiles(query?: GetFilesOptions): Promise<GetFilesResponse>;
Parameter
NameDescription
query GetFilesOptions
Returns
TypeDescription
Promise<GetFilesResponse>

getFiles(query, callback)

getFiles(query: GetFilesOptions, callback: GetFilesCallback): void;
Parameters
NameDescription
query GetFilesOptions
callback GetFilesCallback
Returns
TypeDescription
void

getFiles(callback)

getFiles(callback: GetFilesCallback): void;
Parameter
NameDescription
callback GetFilesCallback
Returns
TypeDescription
void

getFilesStream(query)

getFilesStream(query?: GetFilesOptions): Readable;
Parameter
NameDescription
query GetFilesOptions
Returns
TypeDescription
Readable

getId()

getId(): string;
Returns
TypeDescription
string

getLabels(options)

getLabels(options?: GetLabelsOptions): Promise<GetLabelsResponse>;
Parameter
NameDescription
options GetLabelsOptions
Returns
TypeDescription
Promise<GetLabelsResponse>

getLabels(callback)

getLabels(callback: GetLabelsCallback): void;
Parameter
NameDescription
callback GetLabelsCallback
Returns
TypeDescription
void

getLabels(options, callback)

getLabels(options: GetLabelsOptions, callback: GetLabelsCallback): void;
Parameters
NameDescription
options GetLabelsOptions
callback GetLabelsCallback
Returns
TypeDescription
void

getNotifications(options)

getNotifications(options?: GetNotificationsOptions): Promise<GetNotificationsResponse>;
Parameter
NameDescription
options GetNotificationsOptions
Returns
TypeDescription
Promise<GetNotificationsResponse>

getNotifications(callback)

getNotifications(callback: GetNotificationsCallback): void;
Parameter
NameDescription
callback GetNotificationsCallback
Returns
TypeDescription
void

getNotifications(options, callback)

getNotifications(options: GetNotificationsOptions, callback: GetNotificationsCallback): void;
Parameters
NameDescription
options GetNotificationsOptions
callback GetNotificationsCallback
Returns
TypeDescription
void

getSignedUrl(cfg)

getSignedUrl(cfg: GetBucketSignedUrlConfig): Promise<GetSignedUrlResponse>;
Parameter
NameDescription
cfg GetBucketSignedUrlConfig
Returns
TypeDescription
Promise<GetSignedUrlResponse>

getSignedUrl(cfg, callback)

getSignedUrl(cfg: GetBucketSignedUrlConfig, callback: GetSignedUrlCallback): void;
Parameters
NameDescription
cfg GetBucketSignedUrlConfig
callback GetSignedUrlCallback
Returns
TypeDescription
void

lock(metageneration)

lock(metageneration: number | string): Promise<BucketLockResponse>;
Parameter
NameDescription
metageneration number | string
Returns
TypeDescription
Promise<BucketLockResponse>

lock(metageneration, callback)

lock(metageneration: number | string, callback: BucketLockCallback): void;
Parameters
NameDescription
metageneration number | string
callback BucketLockCallback
Returns
TypeDescription
void

makeAllFilesPublicPrivate_(options)

makeAllFilesPublicPrivate_(options?: MakeAllFilesPublicPrivateOptions): Promise<MakeAllFilesPublicPrivateResponse>;
Parameter
NameDescription
options MakeAllFilesPublicPrivateOptions
Returns
TypeDescription
Promise<MakeAllFilesPublicPrivateResponse>

makeAllFilesPublicPrivate_(callback)

makeAllFilesPublicPrivate_(callback: MakeAllFilesPublicPrivateCallback): void;
Parameter
NameDescription
callback MakeAllFilesPublicPrivateCallback
Returns
TypeDescription
void

makeAllFilesPublicPrivate_(options, callback)

makeAllFilesPublicPrivate_(options: MakeAllFilesPublicPrivateOptions, callback: MakeAllFilesPublicPrivateCallback): void;
Parameters
NameDescription
options MakeAllFilesPublicPrivateOptions
callback MakeAllFilesPublicPrivateCallback
Returns
TypeDescription
void

makePrivate(options)

makePrivate(options?: MakeBucketPrivateOptions): Promise<MakeBucketPrivateResponse>;
Parameter
NameDescription
options MakeBucketPrivateOptions
Returns
TypeDescription
Promise<MakeBucketPrivateResponse>

makePrivate(callback)

makePrivate(callback: MakeBucketPrivateCallback): void;
Parameter
NameDescription
callback MakeBucketPrivateCallback
Returns
TypeDescription
void

makePrivate(options, callback)

makePrivate(options: MakeBucketPrivateOptions, callback: MakeBucketPrivateCallback): void;
Parameters
NameDescription
options MakeBucketPrivateOptions
callback MakeBucketPrivateCallback
Returns
TypeDescription
void

makePublic(options)

makePublic(options?: MakeBucketPublicOptions): Promise<MakeBucketPublicResponse>;
Parameter
NameDescription
options MakeBucketPublicOptions
Returns
TypeDescription
Promise<MakeBucketPublicResponse>

makePublic(callback)

makePublic(callback: MakeBucketPublicCallback): void;
Parameter
NameDescription
callback MakeBucketPublicCallback
Returns
TypeDescription
void

makePublic(options, callback)

makePublic(options: MakeBucketPublicOptions, callback: MakeBucketPublicCallback): void;
Parameters
NameDescription
options MakeBucketPublicOptions
callback MakeBucketPublicCallback
Returns
TypeDescription
void

notification(id)

notification(id: string): Notification;

Get a reference to a Cloud Pub/Sub Notification.

Parameter
NameDescription
id string

ID of notification.

Returns
TypeDescription
Notification

{Notification}

Example

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('my-bucket');
const notification = bucket.notification('1');

removeRetentionPeriod(options)

removeRetentionPeriod(options?: SetBucketMetadataOptions): Promise<SetBucketMetadataResponse>;
Parameter
NameDescription
options SetBucketMetadataOptions
Returns
TypeDescription
Promise<SetBucketMetadataResponse>

removeRetentionPeriod(callback)

removeRetentionPeriod(callback: SetBucketMetadataCallback): void;
Parameter
NameDescription
callback SetBucketMetadataCallback
Returns
TypeDescription
void

removeRetentionPeriod(options, callback)

removeRetentionPeriod(options: SetBucketMetadataOptions, callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
options SetBucketMetadataOptions
callback SetBucketMetadataCallback
Returns
TypeDescription
void

request(reqOpts)

request(reqOpts: DecorateRequestOptions): Promise<RequestResponse>;
Parameter
NameDescription
reqOpts DecorateRequestOptions
Returns
TypeDescription
Promise<RequestResponse>

request(reqOpts, callback)

request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;
Parameters
NameDescription
reqOpts DecorateRequestOptions
callback BodyResponseCallback
Returns
TypeDescription
void

setCorsConfiguration(corsConfiguration, options)

setCorsConfiguration(corsConfiguration: Cors[], options?: SetBucketMetadataOptions): Promise<SetBucketMetadataResponse>;
Parameters
NameDescription
corsConfiguration Cors[]
options SetBucketMetadataOptions
Returns
TypeDescription
Promise<SetBucketMetadataResponse>

setCorsConfiguration(corsConfiguration, callback)

setCorsConfiguration(corsConfiguration: Cors[], callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
corsConfiguration Cors[]
callback SetBucketMetadataCallback
Returns
TypeDescription
void

setCorsConfiguration(corsConfiguration, options, callback)

setCorsConfiguration(corsConfiguration: Cors[], options: SetBucketMetadataOptions, callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
corsConfiguration Cors[]
options SetBucketMetadataOptions
callback SetBucketMetadataCallback
Returns
TypeDescription
void

setLabels(labels, options)

setLabels(labels: Labels, options?: SetLabelsOptions): Promise<SetLabelsResponse>;
Parameters
NameDescription
labels Labels
options SetLabelsOptions
Returns
TypeDescription
Promise<SetLabelsResponse>

setLabels(labels, callback)

setLabels(labels: Labels, callback: SetLabelsCallback): void;
Parameters
NameDescription
labels Labels
callback SetLabelsCallback
Returns
TypeDescription
void

setLabels(labels, options, callback)

setLabels(labels: Labels, options: SetLabelsOptions, callback: SetLabelsCallback): void;
Parameters
NameDescription
labels Labels
options SetLabelsOptions
callback SetLabelsCallback
Returns
TypeDescription
void

setMetadata(metadata, options)

setMetadata(metadata: BucketMetadata, options?: SetMetadataOptions): Promise<SetMetadataResponse<BucketMetadata>>;
Parameters
NameDescription
metadata BucketMetadata
options SetMetadataOptions
Returns
TypeDescription
Promise<SetMetadataResponse<BucketMetadata>>

setMetadata(metadata, callback)

setMetadata(metadata: BucketMetadata, callback: MetadataCallback<BucketMetadata>): void;
Parameters
NameDescription
metadata BucketMetadata
callback MetadataCallback<BucketMetadata>
Returns
TypeDescription
void

setMetadata(metadata, options, callback)

setMetadata(metadata: BucketMetadata, options: SetMetadataOptions, callback: MetadataCallback<BucketMetadata>): void;
Parameters
NameDescription
metadata BucketMetadata
options SetMetadataOptions
callback MetadataCallback<BucketMetadata>
Returns
TypeDescription
void

setRetentionPeriod(duration, options)

setRetentionPeriod(duration: number, options?: SetBucketMetadataOptions): Promise<SetBucketMetadataResponse>;
Parameters
NameDescription
duration number
options SetBucketMetadataOptions
Returns
TypeDescription
Promise<SetBucketMetadataResponse>

setRetentionPeriod(duration, callback)

setRetentionPeriod(duration: number, callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
duration number
callback SetBucketMetadataCallback
Returns
TypeDescription
void

setRetentionPeriod(duration, options, callback)

setRetentionPeriod(duration: number, options: SetBucketMetadataOptions, callback: SetBucketMetadataCallback): void;
Parameters
NameDescription
duration number
options SetBucketMetadataOptions
callback SetBucketMetadataCallback
Returns
TypeDescription
void

setStorageClass(storageClass, options)

setStorageClass(storageClass: string, options?: SetBucketStorageClassOptions): Promise<SetBucketMetadataResponse>;
Parameters
NameDescription
storageClass string
options SetBucketStorageClassOptions
Returns
TypeDescription
Promise<SetBucketMetadataResponse>

setStorageClass(storageClass, callback)

setStorageClass(storageClass: string, callback: SetBucketStorageClassCallback): void;
Parameters
NameDescription
storageClass string
callback SetBucketStorageClassCallback
Returns
TypeDescription
void

setStorageClass(storageClass, options, callback)

setStorageClass(storageClass: string, options: SetBucketStorageClassOptions, callback: SetBucketStorageClassCallback): void;
Parameters
NameDescription
storageClass string
options SetBucketStorageClassOptions
callback SetBucketStorageClassCallback
Returns
TypeDescription
void

setUserProject(userProject)

setUserProject(userProject: string): void;

Set a user project to be billed for all requests made from this Bucket object and any files referenced from this Bucket object.

Parameter
NameDescription
userProject string

The user project.

Returns
TypeDescription
void
Example

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('albums');

bucket.setUserProject('grape-spaceship-123');

upload(pathString, options)

upload(pathString: string, options?: UploadOptions): Promise<UploadResponse>;
Parameters
NameDescription
pathString string
options UploadOptions
Returns
TypeDescription
Promise<UploadResponse>

upload(pathString, options, callback)

upload(pathString: string, options: UploadOptions, callback: UploadCallback): void;
Parameters
NameDescription
pathString string
options UploadOptions
callback UploadCallback
Returns
TypeDescription
void

upload(pathString, callback)

upload(pathString: string, callback: UploadCallback): void;
Parameters
NameDescription
pathString string
callback UploadCallback
Returns
TypeDescription
void