Send feedback
Class Bucket (5.19.1)
Stay organized with collections
Save and categorize content based on your preferences.
Version 5.19.1 keyboard_arrow_down
Create a Bucket object to interact with a Cloud Storage bucket.
Inheritance
ServiceObject
>
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
Properties
acl
iam
instancePreconditionOpts
instancePreconditionOpts ?: PreconditionOptions ;
name
signer
storage
A reference to the Storage associated with this Bucket instance. Bucket#storage {Storage}
userProject
A user project to apply to each request from this bucket. Bucket#userProject {string}
Methods
addLifecycleRule(rule, options)
addLifecycleRule ( rule : LifecycleRule , options ?: AddLifecycleRuleOptions ) : Promise<SetBucketMetadataResponse> ;
Parameters
Name Description rule
LifecycleRule
options
AddLifecycleRuleOptions
Returns
addLifecycleRule(rule, options, callback)
addLifecycleRule ( rule : LifecycleRule , options : AddLifecycleRuleOptions , callback : SetBucketMetadataCallback ) : void ;
Parameters
Returns
addLifecycleRule(rule, callback)
addLifecycleRule ( rule : LifecycleRule , callback : SetBucketMetadataCallback ) : void ;
Parameters
Returns
combine(sources, destination, options)
combine ( sources : string [] | File [], destination : string | File , options ?: CombineOptions ) : Promise<CombineResponse> ;
Parameters
Name Description sources
string[] | File []
destination
string | File
options
CombineOptions
Returns
combine(sources, destination, options, callback)
combine ( sources : string [] | File [], destination : string | File , options : CombineOptions , callback : CombineCallback ) : void ;
Parameters
Returns
combine(sources, destination, callback)
combine ( sources : string [] | File [], destination : string | File , callback : CombineCallback ) : void ;
Parameters
Name Description sources
string[] | File []
destination
string | File
callback
CombineCallback
Returns
createChannel(id, config, options)
createChannel ( id : string , config : CreateChannelConfig , options ?: CreateChannelOptions ) : Promise<CreateChannelResponse> ;
Parameters
Returns
createChannel(id, config, callback)
createChannel ( id : string , config : CreateChannelConfig , callback : CreateChannelCallback ) : void ;
Parameters
Returns
createChannel(id, config, options, callback)
createChannel ( id : string , config : CreateChannelConfig , options : CreateChannelOptions , callback : CreateChannelCallback ) : void ;
Parameters
Returns
createNotification(topic, options)
createNotification ( topic : string , options ?: CreateNotificationOptions ) : Promise<CreateNotificationResponse> ;
Parameters
Returns
createNotification(topic, options, callback)
createNotification ( topic : string , options : CreateNotificationOptions , callback : CreateNotificationCallback ) : void ;
Parameters
Returns
createNotification(topic, callback)
createNotification ( topic : string , callback : CreateNotificationCallback ) : void ;
Parameters
Returns
deleteFiles(query)
deleteFiles ( query ?: DeleteFilesOptions ) : Promise<void> ;
Parameter
Returns
Type Description Promise <void>
deleteFiles(callback)
deleteFiles ( callback : DeleteFilesCallback ) : void ;
Parameter
Returns
deleteFiles(query, callback)
deleteFiles ( query : DeleteFilesOptions , callback : DeleteFilesCallback ) : void ;
Parameters
Returns
deleteLabels(labels)
deleteLabels ( labels ?: string | string []) : Promise<DeleteLabelsResponse> ;
Parameter
Name Description labels
string | string[]
Returns
deleteLabels(callback)
deleteLabels ( callback : DeleteLabelsCallback ) : void ;
Parameter
Returns
deleteLabels(labels, callback)
deleteLabels ( labels : string | string [], callback : DeleteLabelsCallback ) : void ;
Parameters
Returns
disableAutoRetryConditionallyIdempotent_(coreOpts, methodType)
disableAutoRetryConditionallyIdempotent_ ( coreOpts : any , methodType : AvailableServiceObjectMethods ) : void ;
Parameters
Name Description coreOpts
any
methodType
AvailableServiceObjectMethods
Returns
disableRequesterPays()
disableRequesterPays () : Promise<DisableRequesterPaysResponse> ;
Returns
disableRequesterPays(callback)
disableRequesterPays ( callback : DisableRequesterPaysCallback ) : void ;
Parameter
Returns
enableLogging(config)
enableLogging ( config : EnableLoggingOptions ) : Promise<SetBucketMetadataResponse> ;
Parameter
Name Description config
EnableLoggingOptions
Returns
enableLogging(config, callback)
enableLogging ( config : EnableLoggingOptions , callback : SetBucketMetadataCallback ) : void ;
Parameters
Returns
enableRequesterPays()
enableRequesterPays () : Promise<EnableRequesterPaysResponse> ;
Returns
enableRequesterPays(callback)
enableRequesterPays ( callback : EnableRequesterPaysCallback ) : void ;
Parameter
Returns
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
Name Description name
string
The name of the file in this bucket.
options
FileOptions
Configuration options.
Returns
Type Description 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
Returns
getFiles(query, callback)
getFiles ( query : GetFilesOptions , callback : GetFilesCallback ) : void ;
Parameters
Returns
getFiles(callback)
getFiles ( callback : GetFilesCallback ) : void ;
Parameter
Returns
getFilesStream(query)
getFilesStream ( query ?: GetFilesOptions ) : Readable ;
Parameter
Returns
getId()
Returns
getLabels(options)
getLabels ( options ?: GetLabelsOptions ) : Promise<GetLabelsResponse> ;
Parameter
Returns
getLabels(callback)
getLabels ( callback : GetLabelsCallback ) : void ;
Parameter
Returns
getLabels(options, callback)
getLabels ( options : GetLabelsOptions , callback : GetLabelsCallback ) : void ;
Parameters
Returns
getNotifications(options)
getNotifications ( options ?: GetNotificationsOptions ) : Promise<GetNotificationsResponse> ;
Parameter
Returns
getNotifications(callback)
getNotifications ( callback : GetNotificationsCallback ) : void ;
Parameter
Returns
getNotifications(options, callback)
getNotifications ( options : GetNotificationsOptions , callback : GetNotificationsCallback ) : void ;
Parameters
Returns
getSignedUrl(cfg)
getSignedUrl ( cfg : GetBucketSignedUrlConfig ) : Promise<GetSignedUrlResponse> ;
Parameter
Returns
getSignedUrl(cfg, callback)
getSignedUrl ( cfg : GetBucketSignedUrlConfig , callback : GetSignedUrlCallback ) : void ;
Parameters
Returns
lock(metageneration)
lock ( metageneration : number | string ) : Promise<BucketLockResponse> ;
Parameter
Name Description metageneration
number | string
Returns
lock(metageneration, callback)
lock ( metageneration : number | string , callback : BucketLockCallback ) : void ;
Parameters
Returns
makeAllFilesPublicPrivate_(options)
makeAllFilesPublicPrivate_ ( options ?: MakeAllFilesPublicPrivateOptions ) : Promise<MakeAllFilesPublicPrivateResponse> ;
Parameter
Name Description options
MakeAllFilesPublicPrivateOptions
Returns
Type Description Promise <MakeAllFilesPublicPrivateResponse >
makeAllFilesPublicPrivate_(callback)
makeAllFilesPublicPrivate_ ( callback : MakeAllFilesPublicPrivateCallback ) : void ;
Parameter
Name Description callback
MakeAllFilesPublicPrivateCallback
Returns
makeAllFilesPublicPrivate_(options, callback)
makeAllFilesPublicPrivate_ ( options : MakeAllFilesPublicPrivateOptions , callback : MakeAllFilesPublicPrivateCallback ) : void ;
Parameters
Name Description options
MakeAllFilesPublicPrivateOptions
callback
MakeAllFilesPublicPrivateCallback
Returns
makePrivate(options)
makePrivate ( options ?: MakeBucketPrivateOptions ) : Promise<MakeBucketPrivateResponse> ;
Parameter
Returns
makePrivate(callback)
makePrivate ( callback : MakeBucketPrivateCallback ) : void ;
Parameter
Returns
makePrivate(options, callback)
makePrivate ( options : MakeBucketPrivateOptions , callback : MakeBucketPrivateCallback ) : void ;
Parameters
Returns
makePublic(options)
makePublic ( options ?: MakeBucketPublicOptions ) : Promise<MakeBucketPublicResponse> ;
Parameter
Returns
makePublic(callback)
makePublic ( callback : MakeBucketPublicCallback ) : void ;
Parameter
Returns
makePublic(options, callback)
makePublic ( options : MakeBucketPublicOptions , callback : MakeBucketPublicCallback ) : void ;
Parameters
Returns
notification(id)
notification ( id : string ) : Notification ;
Get a reference to a Cloud Pub/Sub Notification.
Parameter
Name Description id
string
ID of notification.
Returns
Type Description 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()
removeRetentionPeriod () : Promise<SetBucketMetadataResponse> ;
Returns
removeRetentionPeriod(callback)
removeRetentionPeriod ( callback : SetBucketMetadataCallback ) : void ;
Parameter
Returns
request(reqOpts)
request ( reqOpts : DecorateRequestOptions ) : Promise <[ ResponseBody , Metadata ]>;
Parameter
Name Description reqOpts
DecorateRequestOptions
Returns
Type Description Promise <[ResponseBody , Metadata ]>
request(reqOpts, callback)
request ( reqOpts : DecorateRequestOptions , callback : BodyResponseCallback ) : void ;
Parameters
Name Description reqOpts
DecorateRequestOptions
callback
BodyResponseCallback
Returns
setCorsConfiguration(corsConfiguration)
setCorsConfiguration ( corsConfiguration : Cors []) : Promise<SetBucketMetadataResponse> ;
Parameter
Name Description corsConfiguration
Cors []
Returns
setCorsConfiguration(corsConfiguration, callback)
setCorsConfiguration ( corsConfiguration : Cors [], callback : SetBucketMetadataCallback ) : void ;
Parameters
Returns
setLabels(labels, options)
setLabels ( labels : Labels , options ?: SetLabelsOptions ) : Promise<SetLabelsResponse> ;
Parameters
Returns
setLabels(labels, callback)
setLabels ( labels : Labels , callback : SetLabelsCallback ) : void ;
Parameters
Returns
setLabels(labels, options, callback)
setLabels ( labels : Labels , options : SetLabelsOptions , callback : SetLabelsCallback ) : void ;
Parameters
Returns
setRetentionPeriod(duration)
setRetentionPeriod ( duration : number ) : Promise<SetBucketMetadataResponse> ;
Parameter
Name Description duration
number
Returns
setRetentionPeriod(duration, callback)
setRetentionPeriod ( duration : number , callback : SetBucketMetadataCallback ) : void ;
Parameters
Returns
setStorageClass(storageClass, options)
setStorageClass ( storageClass : string , options ?: SetBucketStorageClassOptions ) : Promise<SetBucketMetadataResponse> ;
Parameters
Returns
setStorageClass(storageClass, callback)
setStorageClass ( storageClass : string , callback : SetBucketStorageClassCallback ) : void ;
Parameters
Returns
setStorageClass(storageClass, options, callback)
setStorageClass ( storageClass : string , options : SetBucketStorageClassOptions , callback : SetBucketStorageClassCallback ) : void ;
Parameters
Returns
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
Name Description userProject
string
The user project.
Returns
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
Returns
upload(pathString, options, callback)
upload ( pathString : string , options : UploadOptions , callback : UploadCallback ) : void ;
Parameters
Returns
upload(pathString, callback)
upload ( pathString : string , callback : UploadCallback ) : void ;
Parameters
Returns
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-19 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-19 UTC."],[],[]]