Reference documentation and code samples for the Cloud Storage Client class Bucket.
Buckets are the basic containers that hold your data. Everything that you store in Google Cloud Storage must be contained in a bucket.
Example:
use Google\Cloud\Storage\StorageClient;
$storage = new StorageClient();
$bucket = $storage->bucket('my-bucket');
Namespace
Google \ Cloud \ StorageMethods
__construct
| Parameters | |
|---|---|
| Name | Description | 
| connection | Connection\ConnectionInterfaceRepresents a connection to Cloud Storage. This object is created by StorageClient, and should not be instantiated outside of this client. | 
| name | stringThe bucket's name. | 
| info | array[optional] The bucket's metadata. | 
acl
See also:
| Returns | |
|---|---|
| Type | Description | 
| Acl | An ACL instance configured to handle the bucket's access control policies. | 
defaultAcl
See also:
| Returns | |
|---|---|
| Type | Description | 
| Acl | An ACL instance configured to handle the bucket's default object access control policies. | 
exists
Check whether or not the bucket exists.
Example:
if ($bucket->exists()) {
    echo 'Bucket exists!';
}
| Parameter | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
upload
See also:
| Parameters | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Name | Description | ||||||||
| data | string|resource|Psr\Http\Message\StreamInterface|nullThe data to be uploaded. | ||||||||
| options | arrayConfiguration options. | ||||||||
| ↳ name | stringThe name of the destination. Required when data is of type string or null. | ||||||||
| ↳ resumable | boolIndicates whether or not the upload will be performed in a resumable fashion. | ||||||||
| ↳ validate | bool|stringIndicates whether or not validation will be applied using md5 or crc32c hashing functionality. If enabled, and the calculated hash does not match that of the upstream server, the upload will be rejected. Available options are  | ||||||||
| ↳ chunkSize | intIf provided the upload will be done in chunks. The size must be in multiples of 262144 bytes. With chunking you have increased reliability at the risk of higher overhead. It is recommended to not use chunking. | ||||||||
| ↳ uploadProgressCallback | callableIf provided together with $resumable == true the given callable function/method will be called after each successfully uploaded chunk. The callable function/method will receive the number of uploaded bytes after each uploaded chunk as a parameter to this callable. It's useful if you want to create a progress bar when using resumable upload type together with $chunkSize parameter. If $chunkSize is not set the callable function/method will be called only once after the successful file upload. | ||||||||
| ↳ predefinedAcl | stringPredefined ACL to apply to the object. Acceptable values include,  | ||||||||
| ↳ retention | arrayThe full list of available options are outlined at the JSON API docs. 
 | ||||||||
| ↳ metadata | arrayThe full list of available options are outlined at the JSON API docs. 
 | ||||||||
| ↳ encryptionKey | stringA base64 encoded AES-256 customer-supplied encryption key. If you would prefer to manage encryption utilizing the Cloud Key Management Service (KMS) please use the  | ||||||||
| ↳ encryptionKeySHA256 | stringBase64 encoded SHA256 hash of the customer-supplied encryption key. This value will be calculated from the  | ||||||||
| Returns | |
|---|---|
| Type | Description | 
| StorageObject | |
uploadAsync
See also:
| Parameters | |||||||
|---|---|---|---|---|---|---|---|
| Name | Description | ||||||
| data | string|resource|Psr\Http\Message\StreamInterface|nullThe data to be uploaded. | ||||||
| options | arrayConfiguration options. | ||||||
| ↳ name | stringThe name of the destination. Required when data is of type string or null. | ||||||
| ↳ validate | bool|stringIndicates whether or not validation will be applied using md5 or crc32c hashing functionality. If enabled, and the calculated hash does not match that of the upstream server, the upload will be rejected. Available options are  | ||||||
| ↳ predefinedAcl | stringPredefined ACL to apply to the object. Acceptable values include,  | ||||||
| ↳ metadata | arrayThe full list of available options are outlined at the JSON API docs. 
 | ||||||
| ↳ encryptionKey | stringA base64 encoded AES-256 customer-supplied encryption key. If you would prefer to manage encryption utilizing the Cloud Key Management Service (KMS) please use the  | ||||||
| ↳ encryptionKeySHA256 | stringBase64 encoded SHA256 hash of the customer-supplied encryption key. This value will be calculated from the  | ||||||
| Returns | |
|---|---|
| Type | Description | 
| GuzzleHttp\Promise\PromiseInterface<StorageObject> | |
getResumableUploader
| Parameters | |
|---|---|
| Name | Description | 
| data | string|resource|Psr\Http\Message\StreamInterface|nullThe data to be uploaded. | 
| options | arrayConfiguration options. | 
| ↳ name | stringThe name of the destination. Required when data is of type string or null. | 
| ↳ validate | boolIndicates whether or not validation will be applied using md5 hashing functionality. If true and the calculated hash does not match that of the upstream server the upload will be rejected. | 
| ↳ predefinedAcl | stringPredefined ACL to apply to the object. Acceptable values include  | 
| ↳ metadata | arrayThe available options for metadata are outlined at the JSON API docs. | 
| ↳ encryptionKey | stringA base64 encoded AES-256 customer-supplied encryption key. If you would prefer to manage encryption utilizing the Cloud Key Management Service (KMS) please use the $metadata['kmsKeyName'] setting. Please note if using KMS the key ring must use the same location as the bucket. | 
| ↳ encryptionKeySHA256 | stringBase64 encoded SHA256 hash of the customer-supplied encryption key. This value will be calculated from the  | 
| ↳ uploadProgressCallback | callableThe given callable function/method will be called after each successfully uploaded chunk. The callable function/method will receive the number of uploaded bytes after each uploaded chunk as a parameter to this callable. It's useful if you want to create a progress bar when using resumable upload type together with $chunkSize parameter. If $chunkSize is not set the callable function/method will be called only once after the successful file upload. | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Upload\ResumableUploader | |
getStreamableUploader
| Parameters | |
|---|---|
| Name | Description | 
| data | string|resource|Psr\Http\Message\StreamInterfaceThe data to be uploaded. | 
| options | arrayConfiguration options. | 
| ↳ name | stringThe name of the destination. Required when data is of type string or null. | 
| ↳ validate | boolIndicates whether or not validation will be applied using md5 hashing functionality. If true and the calculated hash does not match that of the upstream server the upload will be rejected. | 
| ↳ chunkSize | intIf provided the upload will be done in chunks. The size must be in multiples of 262144 bytes. With chunking you have increased reliability at the risk of higher overhead. It is recommended to not use chunking. | 
| ↳ predefinedAcl | stringPredefined ACL to apply to the object. Acceptable values include,  | 
| ↳ metadata | arrayThe available options for metadata are outlined at the JSON API docs. | 
| ↳ encryptionKey | stringA base64 encoded AES-256 customer-supplied encryption key. If you would prefer to manage encryption utilizing the Cloud Key Management Service (KMS) please use the $metadata['kmsKeyName'] setting. Please note if using KMS the key ring must use the same location as the bucket. | 
| ↳ encryptionKeySHA256 | stringBase64 encoded SHA256 hash of the customer-supplied encryption key. This value will be calculated from the  | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Upload\StreamableUploader | |
object
Lazily instantiates an object. There are no network requests made at this point.
To see the operations that can be performed on an object please see StorageObject.
Example:
$object = $bucket->object('file.txt');
| Parameters | |
|---|---|
| Name | Description | 
| name | stringThe name of the object to request. | 
| options | arrayConfiguration options. | 
| ↳ generation | stringRequest a specific revision of the object. | 
| ↳ encryptionKey | stringA base64 encoded AES-256 customer-supplied encryption key. It will be neccesary to provide this when a key was used during the object's creation. | 
| ↳ encryptionKeySHA256 | stringBase64 encoded SHA256 hash of the customer-supplied encryption key. This value will be calculated from the  | 
| ↳ softDeleted | booleanIf true, returns the metadata of the soft-deleted object. If true, generation must also be specified, and alt=media cannot be specified. | 
| Returns | |
|---|---|
| Type | Description | 
| StorageObject | |
restore
Restores an object.
Example:
$object = $bucket->restore('file.txt');
| Parameters | |
|---|---|
| Name | Description | 
| name | stringThe name of the object to restore. | 
| generation | stringRequest a specific generation of the object. | 
| options | arrayConfiguration Options. | 
| ↳ restoreToken | stringMust be specified when getting a soft-deleted object from an HNS-enabled bucket that has a name and generation conflict with another object in the same bucket. | 
| ↳ ifGenerationMatch | stringMakes the operation conditional on whether the object's current generation matches the given value. | 
| ↳ ifGenerationNotMatch | stringMakes the operation conditional on whether the object's current generation matches the given value. | 
| ↳ ifMetagenerationMatch | stringIf set, only restores if its metageneration matches this value. | 
| ↳ ifMetagenerationNotMatch | stringIf set, only restores if its metageneration does not match this value. | 
| Returns | |
|---|---|
| Type | Description | 
| StorageObject | |
objects
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ delimiter | stringReturns results in a directory-like mode. Results will contain only objects whose names, aside from the prefix, do not contain delimiter. Objects whose names, aside from the prefix, contain delimiter will have their name, truncated after the delimiter, returned in prefixes. Duplicate prefixes are omitted. | 
| ↳ includeFoldersAsPrefixes | boolIf true, will also include folders and managed folders (besides objects) in the returned prefixes. Only applicable if delimiter is set to '/'. | 
| ↳ maxResults | intMaximum number of results to return per request. Defaults to  | 
| ↳ resultLimit | intLimit the number of results returned in total. Defaults to  | 
| ↳ pageToken | stringA previously-returned page token used to resume the loading of results from a specific point. | 
| ↳ prefix | stringFilter results with this prefix. | 
| ↳ projection | stringDetermines which properties to return. May be either  | 
| ↳ versions | boolIf true, lists all versions of an object as distinct results. Defaults to  | 
| ↳ fields | stringSelector which will cause the response to only return the specified fields. | 
| ↳ matchGlob | stringA glob pattern to filter results. The string value must be UTF-8 encoded. See: https://cloud.google.com/storage/docs/json_api/v1/objects/list#list-object-glob | 
| Returns | |
|---|---|
| Type | Description | 
| ObjectIterator | |
createNotification
See also:
| Parameters | |
|---|---|
| Name | Description | 
| topic | string|Google\Cloud\PubSub\TopicThe topic used to publish notifications. | 
| options | arrayConfiguration options. | 
| ↳ custom_attributes | arrayAn optional list of additional attributes to attach to each Cloud PubSub message published for this notification subscription. | 
| ↳ event_types | arrayIf present, only send notifications about listed event types. If empty, sent notifications for all event types. Acceptablue values include  | 
| ↳ object_name_prefix | stringIf present, only apply this notification configuration to object names that begin with this prefix. | 
| ↳ payload_format | stringThe desired content of the Payload. Acceptable values include  | 
| Returns | |
|---|---|
| Type | Description | 
| Notification | |
notification
See also:
| Parameter | |
|---|---|
| Name | Description | 
| id | stringThe ID of the notification to access. | 
| Returns | |
|---|---|
| Type | Description | 
| Notification | |
notifications
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ resultLimit | intLimit the number of results returned in total. Defaults to  | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Iterator\ItemIterator<Notification> | |
delete
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ ifMetagenerationMatch | stringIf set, only deletes the bucket if its metageneration matches this value. | 
| ↳ ifMetagenerationNotMatch | stringIf set, only deletes the bucket if its metageneration does not match this value. | 
| Returns | |
|---|---|
| Type | Description | 
| void | |
update
| Parameters | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Name | Description | ||||||||||
| options | arrayConfiguration options. | ||||||||||
| ↳ ifMetagenerationMatch | stringMakes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value. | ||||||||||
| ↳ ifMetagenerationNotMatch | stringMakes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value. | ||||||||||
| ↳ predefinedAcl | stringPredefined ACL to apply to the bucket. Acceptable values include,  | ||||||||||
| ↳ predefinedDefaultObjectAcl | stringApply a predefined set of default object access controls to this bucket. Acceptable values include,  | ||||||||||
| ↳ projection | stringDetermines which properties to return. May be either  | ||||||||||
| ↳ fields | stringSelector which will cause the response to only return the specified fields. | ||||||||||
| ↳ acl | arrayAccess controls on the bucket. | ||||||||||
| ↳ cors | arrayThe bucket's Cross-Origin Resource Sharing (CORS) configuration. | ||||||||||
| ↳ defaultObjectAcl | arrayDefault access controls to apply to new objects when no ACL is provided. | ||||||||||
| ↳ lifecycle | array|LifecycleThe bucket's lifecycle configuration. | ||||||||||
| ↳ logging | arrayThe bucket's logging configuration, which defines the destination bucket and optional name prefix for the current bucket's logs. | ||||||||||
| ↳ storageClass | stringThe bucket's storage class. This defines how objects in the bucket are stored and determines the SLA and the cost of storage. Acceptable values include the following strings:  | ||||||||||
| ↳ autoclass | arrayThe bucket's autoclass configuration. Buckets can have either StorageClass OLM rules or Autoclass, but not both. When Autoclass is enabled on a bucket, adding StorageClass OLM rules will result in failure. For more information, refer to Storage Autoclass | ||||||||||
| ↳ versioning | arrayThe bucket's versioning configuration. | ||||||||||
| ↳ website | arrayThe bucket's website configuration. | ||||||||||
| ↳ billing | arrayThe bucket's billing configuration. 
 | ||||||||||
| ↳ labels | arrayThe Bucket labels. Labels are represented as an array of keys and values. To remove an existing label, set its value to  | ||||||||||
| ↳ encryption | arrayEncryption configuration used by default for newly inserted objects. 
 | ||||||||||
| ↳ defaultEventBasedHold | boolWhen  | ||||||||||
| ↳ retentionPolicy | arrayDefines the retention policy for a bucket. In order to lock a retention policy, please see Bucket::lockRetentionPolicy(). 
 | ||||||||||
| ↳ iamConfiguration | arrayThe bucket's IAM configuration. 
 | ||||||||||
| Returns | |
|---|---|
| Type | Description | 
| array | |
compose
See also:
| Parameters | |
|---|---|
| Name | Description | 
| sourceObjects | string[]|array<StorageObject>The objects to compose. | 
| name | stringThe name of the composed object. | 
| options | arrayConfiguration options. | 
| ↳ predefinedAcl | stringPredefined ACL to apply to the composed object. Acceptable values include,  | 
| ↳ metadata | arrayMetadata to apply to the composed object. The available options for metadata are outlined at the JSON API docs. | 
| ↳ ifGenerationMatch | stringMakes the operation conditional on whether the object's current generation matches the given value. | 
| ↳ ifMetagenerationMatch | stringMakes the operation conditional on whether the object's current metageneration matches the given value. | 
| Returns | |
|---|---|
| Type | Description | 
| StorageObject | |
info
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ generation | stringIf present, selects a specific soft-deleted version of this bucket instead of the live version. This parameter is required if softDeleted is set to true. | 
| ↳ ifMetagenerationMatch | stringMakes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value. | 
| ↳ ifMetagenerationNotMatch | stringMakes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value. | 
| ↳ projection | stringDetermines which properties to return. May be either  | 
| ↳ softDeleted | boolIf true, returns the soft-deleted bucket. This parameter is required if generation is specified. | 
| Returns | |
|---|---|
| Type | Description | 
| array | |
reload
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ generation | stringIf present, selects a specific soft-deleted version of this bucket instead of the live version. This parameter is required if softDeleted is set to true. | 
| ↳ ifMetagenerationMatch | stringMakes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value. | 
| ↳ ifMetagenerationNotMatch | stringMakes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value. | 
| ↳ projection | stringDetermines which properties to return. May be either  | 
| ↳ softDeleted | boolIf true, returns the soft-deleted bucket. This parameter is required if generation is specified. | 
| Returns | |
|---|---|
| Type | Description | 
| array | |
name
Retrieves the bucket's name.
Example:
echo $bucket->name();
| Returns | |
|---|---|
| Type | Description | 
| string | |
currentLifecycle
| Parameter | |
|---|---|
| Name | Description | 
| options | array[optional] Configuration options. | 
| Returns | |
|---|---|
| Type | Description | 
| Lifecycle | |
isWritable
Returns whether the bucket with the given file prefix is writable.
Tries to create a temporary file as a resumable upload which will not be completed (and cleaned up by GCS).
| Parameter | |
|---|---|
| Name | Description | 
| file | string[optional] File to try to write. | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
iam
See also:
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Iam\Iam | |
lockRetentionPolicy
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ ifMetagenerationMatch | stringOnly locks the retention policy if the bucket's metageneration matches this value. If not provided the locally cached metageneration value will be used, otherwise an exception will be thrown. | 
| Returns | |
|---|---|
| Type | Description | 
| array | |
signedUrl
See also:
| Parameters | |
|---|---|
| Name | Description | 
| expires | Google\Cloud\Core\Timestamp|DateTimeInterface|intSpecifies when the URL will expire. May provide an instance of Google\Cloud\Core\Timestamp, http://php.net/datetimeimmutable, or a UNIX timestamp as an integer. | 
| options | arrayConfiguration Options. | 
| ↳ cname | stringThe CNAME for the bucket, for instance  | 
| ↳ contentMd5 | stringThe MD5 digest value in base64. If you provide this, the client must provide this HTTP header with this same value in its request. If provided, take care to always provide this value as a base64 encoded string. | 
| ↳ contentType | stringIf you provide this value, the client must provide this HTTP header set to the same value. | 
| ↳ forceOpenssl | boolIf true, OpenSSL will be used regardless of whether phpseclib is available. Defaults to  | 
| ↳ headers | arrayIf additional headers are provided, the server will check to make sure that the client provides matching values. Provide headers as a key/value array, where the key is the header name, and the value is an array of header values. Headers with multiple values may provide values as a simple array, or a comma-separated string. For a reference of allowed headers, see Reference Headers. Header values will be trimmed of leading and trailing spaces, multiple spaces within values will be collapsed to a single space, and line breaks will be replaced by an empty string. V2 Signed URLs may not provide  | 
| ↳ credentialsFetcher | FetchAuthTokenInterfaceA credentials fetcher instance. | 
| ↳ keyFile | array[DEPRECATED] @deprecated This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the  | 
| ↳ keyFilePath | string[DEPRECATED] @deprecated This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the  | 
| ↳ queryParams | arrayAdditional query parameters to be included as part of the signed URL query string. For allowed values, see Reference Headers. | 
| ↳ version | stringOne of "v2" or "v4". Defaults to*  | 
| Returns | |
|---|---|
| Type | Description | 
| string | |
generateSignedPostPolicyV4
See also:
| Parameters | |
|---|---|
| Name | Description | 
| objectName | stringThe path to the file in Google Cloud Storage, relative to the bucket. | 
| expires | Google\Cloud\Core\Timestamp|DateTimeInterface|intSpecifies when the URL will expire. May provide an instance of Google\Cloud\Core\Timestamp, http://php.net/datetimeimmutable, or a UNIX timestamp as an integer. | 
| options | arrayConfiguration options | 
| ↳ bucketBoundHostname | stringThe hostname for the bucket, for instance  | 
| ↳ conditions | arrayA list of arrays containing policy matching conditions (e.g.  | 
| ↳ fields | arrayAdditional form fields (do not include  | 
| ↳ forceOpenssl | boolIf true, OpenSSL will be used regardless of whether phpseclib is available. Defaults to  | 
| ↳ credentialsFetcher | FetchAuthTokenInterfaceA credentials fetcher instance. | 
| ↳ keyFile | array[DEPRECATED] @deprecated This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the  | 
| ↳ keyFilePath | string[DEPRECATED] @deprecated This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the  | 
| ↳ scopes | string|arrayOne or more authentication scopes to be used with a key file. This option is ignored unless  | 
| ↳ virtualHostedStyle | boolIf  | 
| Returns | |
|---|---|
| Type | Description | 
| array | An associative array, containing (string) `uri` and (array) `fields` keys. | 
static::lifecycle
| Parameter | |
|---|---|
| Name | Description | 
| lifecycle | array[optional] A lifecycle configuration. Please see here for the expected structure. | 
| Returns | |
|---|---|
| Type | Description | 
| Lifecycle | |
Constants
NOTIFICATION_TEMPLATE
Value: '//pubsub.googleapis.com/%s'TOPIC_TEMPLATE
Value: 'projects/%s/topics/%s'TOPIC_REGEX
Value: '/projects\/[^\/]*\/topics\/(.*)/'