Class Bucket (7.3.2)
Stay organized with collections
Save and categorize content based on your preferences.
Create a Bucket object to interact with a Cloud Storage 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
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>;
addLifecycleRule(rule, options, callback)
addLifecycleRule(rule: LifecycleRule | LifecycleRule[], options: AddLifecycleRuleOptions, callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
addLifecycleRule(rule, callback)
addLifecycleRule(rule: LifecycleRule | LifecycleRule[], callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
combine(sources, destination, options)
combine(sources: string[] | File[], destination: string | File, options?: CombineOptions): Promise<CombineResponse>;
combine(sources, destination, options, callback)
combine(sources: string[] | File[], destination: string | File, options: CombineOptions, callback: CombineCallback): void;
Returns |
---|
Type | Description |
void | |
combine(sources, destination, callback)
combine(sources: string[] | File[], destination: string | File, callback: CombineCallback): void;
Returns |
---|
Type | Description |
void | |
createChannel(id, config, options)
createChannel(id: string, config: CreateChannelConfig, options?: CreateChannelOptions): Promise<CreateChannelResponse>;
createChannel(id, config, callback)
createChannel(id: string, config: CreateChannelConfig, callback: CreateChannelCallback): void;
Returns |
---|
Type | Description |
void | |
createChannel(id, config, options, callback)
createChannel(id: string, config: CreateChannelConfig, options: CreateChannelOptions, callback: CreateChannelCallback): void;
Returns |
---|
Type | Description |
void | |
createNotification(topic, options)
createNotification(topic: string, options?: CreateNotificationOptions): Promise<CreateNotificationResponse>;
createNotification(topic, options, callback)
createNotification(topic: string, options: CreateNotificationOptions, callback: CreateNotificationCallback): void;
Returns |
---|
Type | Description |
void | |
createNotification(topic, callback)
createNotification(topic: string, callback: CreateNotificationCallback): void;
Returns |
---|
Type | Description |
void | |
deleteFiles(query)
deleteFiles(query?: DeleteFilesOptions): Promise<void>;
Returns |
---|
Type | Description |
Promise<void> | |
deleteFiles(callback)
deleteFiles(callback: DeleteFilesCallback): void;
Returns |
---|
Type | Description |
void | |
deleteFiles(query, callback)
deleteFiles(query: DeleteFilesOptions, callback: DeleteFilesCallback): void;
Returns |
---|
Type | Description |
void | |
deleteLabels(labels)
deleteLabels(labels?: string | string[]): Promise<DeleteLabelsResponse>;
Parameter |
---|
Name | Description |
labels |
string | string[]
|
deleteLabels(options)
deleteLabels(options: DeleteLabelsOptions): Promise<DeleteLabelsResponse>;
Parameter |
---|
Name | Description |
options |
DeleteLabelsOptions
|
deleteLabels(callback)
deleteLabels(callback: DeleteLabelsCallback): void;
Returns |
---|
Type | Description |
void | |
deleteLabels(labels, options)
deleteLabels(labels: string | string[], options: DeleteLabelsOptions): Promise<DeleteLabelsResponse>;
Parameters |
---|
Name | Description |
labels |
string | string[]
|
options |
DeleteLabelsOptions
|
deleteLabels(labels, callback)
deleteLabels(labels: string | string[], callback: DeleteLabelsCallback): void;
Returns |
---|
Type | Description |
void | |
deleteLabels(labels, options, callback)
deleteLabels(labels: string | string[], options: DeleteLabelsOptions, callback: DeleteLabelsCallback): void;
Parameters |
---|
Name | Description |
labels |
string | string[]
|
options |
DeleteLabelsOptions
|
callback |
DeleteLabelsCallback
|
Returns |
---|
Type | Description |
void | |
disableAutoRetryConditionallyIdempotent_(coreOpts, methodType, localPreconditionOptions)
disableAutoRetryConditionallyIdempotent_(coreOpts: any, methodType: AvailableServiceObjectMethods, localPreconditionOptions?: PreconditionOptions): void;
Parameters |
---|
Name | Description |
coreOpts |
any
|
methodType |
AvailableServiceObjectMethods
|
localPreconditionOptions |
PreconditionOptions
|
Returns |
---|
Type | Description |
void | |
disableRequesterPays(options)
disableRequesterPays(options?: DisableRequesterPaysOptions): Promise<DisableRequesterPaysResponse>;
Parameter |
---|
Name | Description |
options |
DisableRequesterPaysOptions
|
disableRequesterPays(callback)
disableRequesterPays(callback: DisableRequesterPaysCallback): void;
Returns |
---|
Type | Description |
void | |
disableRequesterPays(options, callback)
disableRequesterPays(options: DisableRequesterPaysOptions, callback: DisableRequesterPaysCallback): void;
Returns |
---|
Type | Description |
void | |
enableLogging(config)
enableLogging(config: EnableLoggingOptions): Promise<SetBucketMetadataResponse>;
Parameter |
---|
Name | Description |
config |
EnableLoggingOptions
|
enableLogging(config, callback)
enableLogging(config: EnableLoggingOptions, callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
enableRequesterPays(options)
enableRequesterPays(options?: EnableRequesterPaysOptions): Promise<EnableRequesterPaysResponse>;
Parameter |
---|
Name | Description |
options |
EnableRequesterPaysOptions
|
enableRequesterPays(callback)
enableRequesterPays(callback: EnableRequesterPaysCallback): void;
Returns |
---|
Type | Description |
void | |
enableRequesterPays(options, callback)
enableRequesterPays(options: EnableRequesterPaysOptions, callback: EnableRequesterPaysCallback): void;
Returns |
---|
Type | Description |
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 |
---|
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>;
getFiles(query, callback)
getFiles(query: GetFilesOptions, callback: GetFilesCallback): void;
Returns |
---|
Type | Description |
void | |
getFiles(callback)
getFiles(callback: GetFilesCallback): void;
Returns |
---|
Type | Description |
void | |
getFilesStream(query)
getFilesStream(query?: GetFilesOptions): Readable;
Returns |
---|
Type | Description |
Readable | |
getId()
Returns |
---|
Type | Description |
string | |
getLabels(options)
getLabels(options?: GetLabelsOptions): Promise<GetLabelsResponse>;
getLabels(callback)
getLabels(callback: GetLabelsCallback): void;
Returns |
---|
Type | Description |
void | |
getLabels(options, callback)
getLabels(options: GetLabelsOptions, callback: GetLabelsCallback): void;
Returns |
---|
Type | Description |
void | |
getNotifications(options)
getNotifications(options?: GetNotificationsOptions): Promise<GetNotificationsResponse>;
getNotifications(callback)
getNotifications(callback: GetNotificationsCallback): void;
Returns |
---|
Type | Description |
void | |
getNotifications(options, callback)
getNotifications(options: GetNotificationsOptions, callback: GetNotificationsCallback): void;
Returns |
---|
Type | Description |
void | |
getSignedUrl(cfg)
getSignedUrl(cfg: GetBucketSignedUrlConfig): Promise<GetSignedUrlResponse>;
getSignedUrl(cfg, callback)
getSignedUrl(cfg: GetBucketSignedUrlConfig, callback: GetSignedUrlCallback): void;
Returns |
---|
Type | Description |
void | |
lock(metageneration)
lock(metageneration: number | string): Promise<BucketLockResponse>;
Parameter |
---|
Name | Description |
metageneration |
number | string
|
lock(metageneration, callback)
lock(metageneration: number | string, callback: BucketLockCallback): void;
Returns |
---|
Type | Description |
void | |
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 |
---|
Type | Description |
void | |
makeAllFilesPublicPrivate_(options, callback)
makeAllFilesPublicPrivate_(options: MakeAllFilesPublicPrivateOptions, callback: MakeAllFilesPublicPrivateCallback): void;
Parameters |
---|
Name | Description |
options |
MakeAllFilesPublicPrivateOptions
|
callback |
MakeAllFilesPublicPrivateCallback
|
Returns |
---|
Type | Description |
void | |
makePrivate(options)
makePrivate(options?: MakeBucketPrivateOptions): Promise<MakeBucketPrivateResponse>;
makePrivate(callback)
makePrivate(callback: MakeBucketPrivateCallback): void;
Returns |
---|
Type | Description |
void | |
makePrivate(options, callback)
makePrivate(options: MakeBucketPrivateOptions, callback: MakeBucketPrivateCallback): void;
Returns |
---|
Type | Description |
void | |
makePublic(options)
makePublic(options?: MakeBucketPublicOptions): Promise<MakeBucketPublicResponse>;
makePublic(callback)
makePublic(callback: MakeBucketPublicCallback): void;
Returns |
---|
Type | Description |
void | |
makePublic(options, callback)
makePublic(options: MakeBucketPublicOptions, callback: MakeBucketPublicCallback): void;
Returns |
---|
Type | Description |
void | |
notification(id)
notification(id: string): Notification;
Get a reference to a Cloud Pub/Sub Notification.
Parameter |
---|
Name | Description |
id |
string
ID of 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>;
removeRetentionPeriod(callback)
removeRetentionPeriod(callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
removeRetentionPeriod(options, callback)
removeRetentionPeriod(options: SetBucketMetadataOptions, callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
request(reqOpts)
request(reqOpts: DecorateRequestOptions): Promise<RequestResponse>;
Parameter |
---|
Name | Description |
reqOpts |
DecorateRequestOptions
|
Returns |
---|
Type | Description |
Promise<RequestResponse> | |
request(reqOpts, callback)
request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;
Parameters |
---|
Name | Description |
reqOpts |
DecorateRequestOptions
|
callback |
BodyResponseCallback
|
Returns |
---|
Type | Description |
void | |
setCorsConfiguration(corsConfiguration, options)
setCorsConfiguration(corsConfiguration: Cors[], options?: SetBucketMetadataOptions): Promise<SetBucketMetadataResponse>;
setCorsConfiguration(corsConfiguration, callback)
setCorsConfiguration(corsConfiguration: Cors[], callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
setCorsConfiguration(corsConfiguration, options, callback)
setCorsConfiguration(corsConfiguration: Cors[], options: SetBucketMetadataOptions, callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
setLabels(labels, options)
setLabels(labels: Labels, options?: SetLabelsOptions): Promise<SetLabelsResponse>;
setLabels(labels, callback)
setLabels(labels: Labels, callback: SetLabelsCallback): void;
Returns |
---|
Type | Description |
void | |
setLabels(labels, options, callback)
setLabels(labels: Labels, options: SetLabelsOptions, callback: SetLabelsCallback): void;
Returns |
---|
Type | Description |
void | |
setMetadata(metadata: BucketMetadata, options?: SetMetadataOptions): Promise<SetMetadataResponse<BucketMetadata>>;
Parameters |
---|
Name | Description |
metadata |
BucketMetadata
|
options |
SetMetadataOptions
|
setMetadata(metadata: BucketMetadata, callback: MetadataCallback<BucketMetadata>): void;
Returns |
---|
Type | Description |
void | |
setMetadata(metadata: BucketMetadata, options: SetMetadataOptions, callback: MetadataCallback<BucketMetadata>): void;
Returns |
---|
Type | Description |
void | |
setRetentionPeriod(duration, options)
setRetentionPeriod(duration: number, options?: SetBucketMetadataOptions): Promise<SetBucketMetadataResponse>;
setRetentionPeriod(duration, callback)
setRetentionPeriod(duration: number, callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
setRetentionPeriod(duration, options, callback)
setRetentionPeriod(duration: number, options: SetBucketMetadataOptions, callback: SetBucketMetadataCallback): void;
Returns |
---|
Type | Description |
void | |
setStorageClass(storageClass, options)
setStorageClass(storageClass: string, options?: SetBucketStorageClassOptions): Promise<SetBucketMetadataResponse>;
setStorageClass(storageClass, callback)
setStorageClass(storageClass: string, callback: SetBucketStorageClassCallback): void;
Returns |
---|
Type | Description |
void | |
setStorageClass(storageClass, options, callback)
setStorageClass(storageClass: string, options: SetBucketStorageClassOptions, callback: SetBucketStorageClassCallback): void;
Returns |
---|
Type | Description |
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 |
---|
Name | Description |
userProject |
string
The user project.
|
Returns |
---|
Type | Description |
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>;
upload(pathString, options, callback)
upload(pathString: string, options: UploadOptions, callback: UploadCallback): void;
Returns |
---|
Type | Description |
void | |
upload(pathString, callback)
upload(pathString: string, callback: UploadCallback): void;
Returns |
---|
Type | Description |
void | |
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-09-19 UTC.
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-09-19 UTC."}
[[["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-09-19 UTC."]]