Send feedback
Class Bucket (6.5.4) Stay organized with collections
Save and categorize content based on your preferences.
Version 6.5.4 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
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
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
|
LifecycleRule
[],
options
?:
AddLifecycleRuleOptions
)
:
Promise<SetBucketMetadataResponse>
;
Parameters Name
Description
rule
LifecycleRule
| LifecycleRule
[]
options
AddLifecycleRuleOptions
Returns
addLifecycleRule(rule, options, callback)
addLifecycleRule
(
rule
:
LifecycleRule
|
LifecycleRule
[],
options
:
AddLifecycleRuleOptions
,
callback
:
SetBucketMetadataCallback
)
:
void
;
Parameters
Returns
addLifecycleRule(rule, callback)
addLifecycleRule
(
rule
:
LifecycleRule
|
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
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(options)
deleteLabels
(
options
:
DeleteLabelsOptions
)
:
Promise<DeleteLabelsResponse>
;
Parameter
Returns
deleteLabels(callback)
deleteLabels
(
callback
:
DeleteLabelsCallback
)
:
void
;
Parameter
Returns
deleteLabels(labels, options)
deleteLabels
(
labels
:
string
|
string
[],
options
:
DeleteLabelsOptions
)
:
Promise<DeleteLabelsResponse>
;
Parameters Name
Description
labels
string | string[]
options
DeleteLabelsOptions
Returns
deleteLabels(labels, callback)
deleteLabels
(
labels
:
string
|
string
[],
callback
:
DeleteLabelsCallback
)
:
void
;
Parameters
Returns
deleteLabels(labels, options, callback)
deleteLabels
(
labels
:
string
|
string
[],
options
:
DeleteLabelsOptions
,
callback
:
DeleteLabelsCallback
)
:
void
;
Parameters
Returns
disableAutoRetryConditionallyIdempotent_(coreOpts, methodType, localPreconditionOptions)
disableAutoRetryConditionallyIdempotent_
(
coreOpts
:
any
,
methodType
:
AvailableServiceObjectMethods
,
localPreconditionOptions
?:
PreconditionOptions
)
:
void
;
Parameters Name
Description
coreOpts
any
methodType
AvailableServiceObjectMethods
localPreconditionOptions
PreconditionOptions
Returns
disableRequesterPays(options)
disableRequesterPays
(
options
?:
DisableRequesterPaysOptions
)
:
Promise<DisableRequesterPaysResponse>
;
Parameter Name
Description
options
DisableRequesterPaysOptions
Returns
disableRequesterPays(callback)
disableRequesterPays
(
callback
:
DisableRequesterPaysCallback
)
:
void
;
Parameter
Returns
disableRequesterPays(options, callback)
disableRequesterPays
(
options
:
DisableRequesterPaysOptions
,
callback
:
DisableRequesterPaysCallback
)
:
void
;
Parameters
Returns
enableLogging(config)
enableLogging
(
config
:
EnableLoggingOptions
)
:
Promise<SetBucketMetadataResponse>
;
Parameter
Returns
enableLogging(config, callback)
enableLogging
(
config
:
EnableLoggingOptions
,
callback
:
SetBucketMetadataCallback
)
:
void
;
Parameters
Returns
enableRequesterPays(options)
enableRequesterPays
(
options
?:
EnableRequesterPaysOptions
)
:
Promise<EnableRequesterPaysResponse>
;
Parameter Name
Description
options
EnableRequesterPaysOptions
Returns
enableRequesterPays(callback)
enableRequesterPays
(
callback
:
EnableRequesterPaysCallback
)
:
void
;
Parameter
Returns
enableRequesterPays(options, callback)
enableRequesterPays
(
options
:
EnableRequesterPaysOptions
,
callback
:
EnableRequesterPaysCallback
)
:
void
;
Parameters
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
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
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
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
Returns
removeRetentionPeriod(callback)
removeRetentionPeriod
(
callback
:
SetBucketMetadataCallback
)
:
void
;
Parameter
Returns
removeRetentionPeriod(options, callback)
removeRetentionPeriod
(
options
:
SetBucketMetadataOptions
,
callback
:
SetBucketMetadataCallback
)
:
void
;
Parameters
Returns
request(reqOpts)
request
(
reqOpts
:
DecorateRequestOptions
)
:
Promise
< [
ResponseBody
,
Metadata
]>;
Parameter Name
Description
reqOpts
DecorateRequestOptions
Returns
request(reqOpts, callback)
request
(
reqOpts
:
DecorateRequestOptions
,
callback
:
BodyResponseCallback
)
:
void
;
Parameters Name
Description
reqOpts
DecorateRequestOptions
callback
BodyResponseCallback
Returns
setCorsConfiguration(corsConfiguration, options)
setCorsConfiguration
(
corsConfiguration
:
Cors
[],
options
?:
SetBucketMetadataOptions
)
:
Promise<SetBucketMetadataResponse>
;
Parameters
Returns
setCorsConfiguration(corsConfiguration, callback)
setCorsConfiguration
(
corsConfiguration
:
Cors
[],
callback
:
SetBucketMetadataCallback
)
:
void
;
Parameters
Returns
setCorsConfiguration(corsConfiguration, options, callback)
setCorsConfiguration
(
corsConfiguration
:
Cors
[],
options
:
SetBucketMetadataOptions
,
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
setMetadata
(
metadata
:
Metadata
,
options
?:
SetMetadataOptions
)
:
Promise<SetMetadataResponse>
;
Parameters
Returns
setMetadata
(
metadata
:
Metadata
,
callback
:
MetadataCallback
)
:
void
;
Parameters
Returns
setMetadata
(
metadata
:
Metadata
,
options
:
SetMetadataOptions
,
callback
:
MetadataCallback
)
:
void
;
Parameters
Returns
setRetentionPeriod(duration, options)
setRetentionPeriod
(
duration
:
number
,
options
?:
SetBucketMetadataOptions
)
:
Promise<SetBucketMetadataResponse>
;
Parameters
Returns
setRetentionPeriod(duration, callback)
setRetentionPeriod
(
duration
:
number
,
callback
:
SetBucketMetadataCallback
)
:
void
;
Parameters
Returns
setRetentionPeriod(duration, options, callback)
setRetentionPeriod
(
duration
:
number
,
options
:
SetBucketMetadataOptions
,
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
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 2025-09-04 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 2025-09-04 UTC."],[],[],null,[]]