1.62.2 (latest) 1.62.1 1.61.0 1.60.0 1.59.0 1.58.0 1.57.1 1.56.0 1.55.0 1.54.0 1.53.0 1.52.0 1.51.0 1.50.0 1.49.0 1.48.1 1.47.0 1.46.0 1.45.0 1.44.0 1.43.0 1.42.0 1.41.0 1.40.0 1.39.0 1.38.0 1.37.0 1.36.2 1.35.0 Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Bucket.

## Bucket

Represents a Storage bucket. Belongs to a Project and has many Files.

## Inherits

- Object

## Example

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
```

## Methods

### #acl

```ruby
def acl() -> Bucket::Acl
```
The [Acl](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Acl.md.txt "Google::Cloud::Storage::Bucket::Acl (class)") instance used to control access to the bucket.


<br />

A bucket has owners, writers, and readers. Permissions can be granted
to an individual user's email address, a group's email address, as
well as many predefined lists.
**Returns**

- ([Bucket::Acl](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Acl.md.txt))
**Examples**

Grant access to a user by prepending `"user-"` to an email:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"

email = "heidi@example.net"
bucket.acl.add_reader "user-#{email}"
```

Grant access to a group by prepending `"group-"` to an email:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"

email = "authors@example.net"
bucket.acl.add_reader "group-#{email}"
```

Or, grant access via a predefined permissions list:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"

bucket.acl.public!
```

### #api_url

```ruby
def api_url() -> String
```
A URL that can be used to access the bucket using the REST API.
**Returns**

- (String)

### #autoclass

```ruby
def autoclass() -> Google::Apis::StorageV1::Bucket::Autoclass
```
The autoclass configuration of the bucket
**Returns**

- (Google::Apis::StorageV1::Bucket::Autoclass)

### #autoclass_enabled

```ruby
def autoclass_enabled() -> Boolean
```
Whether Autoclass is enabled for the bucket.
**Returns**

- (Boolean)

### #autoclass_enabled=

```ruby
def autoclass_enabled=(toggle)
```
Updates bucket's autoclass configuration. This defines the default class for objects in the
bucket and down/up-grades the storage class of objects based on the access patterns.
Accepted values are `:false`, and `:true`.


<br />

For more information, see [Storage
Classes](https://cloud.google.com/storage/docs/using-autoclass).
**Parameter**

- **toggle** (Boolean) --- for autoclass configuration of the bucket.

### #autoclass_terminal_storage_class

```ruby
def autoclass_terminal_storage_class() -> String
```
Terminal Storage class of the autoclass
**Returns**

- (String)

### #autoclass_terminal_storage_class_update_time

```ruby
def autoclass_terminal_storage_class_update_time() -> DateTime
```
Update time at which the autoclass terminal storage class was last modified
**Returns**

- (DateTime)

### #autoclass_toggle_time

```ruby
def autoclass_toggle_time() -> DateTime
```
Toggle time of the autoclass
**Returns**

- (DateTime)

### #combine

```ruby
def combine(sources, destination, acl: nil, encryption_key: nil, if_source_generation_match: nil, if_generation_match: nil, if_metageneration_match: nil, delete_source_objects: nil) -> Google::Cloud::Storage::File
```
**Alias Of** : [#compose](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_compose_instance_) Concatenates a list of existing files in the bucket into a new file in
the bucket. There is a limit (currently 32) to the number of files
that can be composed in a single operation.


<br />

To compose files encrypted with a customer-supplied encryption key,
use the `encryption_key` option. All source files must have been
encrypted with the same key, and the resulting destination file will
also be encrypted with the same key.
**Parameters**

- **sources** (Array\<String, Google::Cloud::Storage::File\>) --- The list of source file names or objects that will be concatenated into a single file.
- **destination** (String) --- The name of the new file.
- **acl** (String) *(defaults to: nil)* ---

  A predefined set of access controls to apply to
  this file.

  Acceptable values are:
  - `auth`, `auth_read`, `authenticated`, `authenticated_read`, `authenticatedRead` - File owner gets OWNER access, and allAuthenticatedUsers get READER access.
  - `owner_full`, `bucketOwnerFullControl` - File owner gets OWNER access, and project team owners get OWNER access.
  - `owner_read`, `bucketOwnerRead` - File owner gets OWNER access, and project team owners get READER access.
  - `private` - File owner gets OWNER access.
  - `project_private`, `projectPrivate` - File owner gets OWNER access, and project team members get access according to their roles.
  - `public`, `public_read`, `publicRead` - File owner gets OWNER access, and allUsers get READER access.
- **encryption_key** (String, nil) *(defaults to: nil)* --- Optional. The customer-supplied, AES-256 encryption key used to encrypt the source files, if one was used. All source files must have been encrypted with the same key, and the resulting destination file will also be encrypted with the key.
- **if_source_generation_match** (Array\<Integer\>) *(defaults to: nil)* --- Makes the operation conditional on whether the source files' current generations match the given values. The list must match `sources` item-to-item.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the destination file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the destination file's current metageneration matches the given value.
- **delete_source_objects** (Boolean) *(defaults to: nil)* --- If true, the source objects will be deleted after the composition operation is successful.
**Yields**

- (file) --- A block yielding a delegate file object for setting the properties of the destination file.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)) --- The new file.
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

sources = ["path/to/my-file-1.ext", "path/to/my-file-2.ext"]

new_file = bucket.compose sources, "path/to/new-file.ext"
```

Set the properties of the new file in a block:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

sources = ["path/to/my-file-1.ext", "path/to/my-file-2.ext"]

new_file = bucket.compose sources, "path/to/new-file.ext" do |f|
  f.cache_control = "private, max-age=0, no-cache"
  f.content_disposition = "inline; filename=filename.ext"
  f.content_encoding = "deflate"
  f.content_language = "de"
  f.content_type = "application/json"
end
```

Specify the generation of source files (but skip retrieval):

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

file_1 = bucket.file "path/to/my-file-1.ext",
                     generation: 1490390259479000, skip_lookup: true
file_2 = bucket.file "path/to/my-file-2.ext",
                     generation: 1490310974144000, skip_lookup: true

new_file = bucket.compose [file_1, file_2], "path/to/new-file.ext"
```

### #compose

```ruby
def compose(sources, destination, acl: nil, encryption_key: nil, if_source_generation_match: nil, if_generation_match: nil, if_metageneration_match: nil, delete_source_objects: nil) -> Google::Cloud::Storage::File
```
**Aliases**

- [#compose_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_compose_file_instance_)
- [#combine](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_combine_instance_)
Concatenates a list of existing files in the bucket into a new file in
the bucket. There is a limit (currently 32) to the number of files
that can be composed in a single operation.


<br />

To compose files encrypted with a customer-supplied encryption key,
use the `encryption_key` option. All source files must have been
encrypted with the same key, and the resulting destination file will
also be encrypted with the same key.
**Parameters**

- **sources** (Array\<String, Google::Cloud::Storage::File\>) --- The list of source file names or objects that will be concatenated into a single file.
- **destination** (String) --- The name of the new file.
- **acl** (String) *(defaults to: nil)* ---

  A predefined set of access controls to apply to
  this file.

  Acceptable values are:
  - `auth`, `auth_read`, `authenticated`, `authenticated_read`, `authenticatedRead` - File owner gets OWNER access, and allAuthenticatedUsers get READER access.
  - `owner_full`, `bucketOwnerFullControl` - File owner gets OWNER access, and project team owners get OWNER access.
  - `owner_read`, `bucketOwnerRead` - File owner gets OWNER access, and project team owners get READER access.
  - `private` - File owner gets OWNER access.
  - `project_private`, `projectPrivate` - File owner gets OWNER access, and project team members get access according to their roles.
  - `public`, `public_read`, `publicRead` - File owner gets OWNER access, and allUsers get READER access.
- **encryption_key** (String, nil) *(defaults to: nil)* --- Optional. The customer-supplied, AES-256 encryption key used to encrypt the source files, if one was used. All source files must have been encrypted with the same key, and the resulting destination file will also be encrypted with the key.
- **if_source_generation_match** (Array\<Integer\>) *(defaults to: nil)* --- Makes the operation conditional on whether the source files' current generations match the given values. The list must match `sources` item-to-item.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the destination file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the destination file's current metageneration matches the given value.
- **delete_source_objects** (Boolean) *(defaults to: nil)* --- If true, the source objects will be deleted after the composition operation is successful.
**Yields**

- (file) --- A block yielding a delegate file object for setting the properties of the destination file.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)) --- The new file.
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

sources = ["path/to/my-file-1.ext", "path/to/my-file-2.ext"]

new_file = bucket.compose sources, "path/to/new-file.ext"
```

Set the properties of the new file in a block:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

sources = ["path/to/my-file-1.ext", "path/to/my-file-2.ext"]

new_file = bucket.compose sources, "path/to/new-file.ext" do |f|
  f.cache_control = "private, max-age=0, no-cache"
  f.content_disposition = "inline; filename=filename.ext"
  f.content_encoding = "deflate"
  f.content_language = "de"
  f.content_type = "application/json"
end
```

Specify the generation of source files (but skip retrieval):

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

file_1 = bucket.file "path/to/my-file-1.ext",
                     generation: 1490390259479000, skip_lookup: true
file_2 = bucket.file "path/to/my-file-2.ext",
                     generation: 1490310974144000, skip_lookup: true

new_file = bucket.compose [file_1, file_2], "path/to/new-file.ext"
```

### #compose_file

```ruby
def compose_file(sources, destination, acl: nil, encryption_key: nil, if_source_generation_match: nil, if_generation_match: nil, if_metageneration_match: nil, delete_source_objects: nil) -> Google::Cloud::Storage::File
```
**Alias Of** : [#compose](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_compose_instance_) Concatenates a list of existing files in the bucket into a new file in
the bucket. There is a limit (currently 32) to the number of files
that can be composed in a single operation.


<br />

To compose files encrypted with a customer-supplied encryption key,
use the `encryption_key` option. All source files must have been
encrypted with the same key, and the resulting destination file will
also be encrypted with the same key.
**Parameters**

- **sources** (Array\<String, Google::Cloud::Storage::File\>) --- The list of source file names or objects that will be concatenated into a single file.
- **destination** (String) --- The name of the new file.
- **acl** (String) *(defaults to: nil)* ---

  A predefined set of access controls to apply to
  this file.

  Acceptable values are:
  - `auth`, `auth_read`, `authenticated`, `authenticated_read`, `authenticatedRead` - File owner gets OWNER access, and allAuthenticatedUsers get READER access.
  - `owner_full`, `bucketOwnerFullControl` - File owner gets OWNER access, and project team owners get OWNER access.
  - `owner_read`, `bucketOwnerRead` - File owner gets OWNER access, and project team owners get READER access.
  - `private` - File owner gets OWNER access.
  - `project_private`, `projectPrivate` - File owner gets OWNER access, and project team members get access according to their roles.
  - `public`, `public_read`, `publicRead` - File owner gets OWNER access, and allUsers get READER access.
- **encryption_key** (String, nil) *(defaults to: nil)* --- Optional. The customer-supplied, AES-256 encryption key used to encrypt the source files, if one was used. All source files must have been encrypted with the same key, and the resulting destination file will also be encrypted with the key.
- **if_source_generation_match** (Array\<Integer\>) *(defaults to: nil)* --- Makes the operation conditional on whether the source files' current generations match the given values. The list must match `sources` item-to-item.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the destination file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the destination file's current metageneration matches the given value.
- **delete_source_objects** (Boolean) *(defaults to: nil)* --- If true, the source objects will be deleted after the composition operation is successful.
**Yields**

- (file) --- A block yielding a delegate file object for setting the properties of the destination file.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)) --- The new file.
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

sources = ["path/to/my-file-1.ext", "path/to/my-file-2.ext"]

new_file = bucket.compose sources, "path/to/new-file.ext"
```

Set the properties of the new file in a block:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

sources = ["path/to/my-file-1.ext", "path/to/my-file-2.ext"]

new_file = bucket.compose sources, "path/to/new-file.ext" do |f|
  f.cache_control = "private, max-age=0, no-cache"
  f.content_disposition = "inline; filename=filename.ext"
  f.content_encoding = "deflate"
  f.content_language = "de"
  f.content_type = "application/json"
end
```

Specify the generation of source files (but skip retrieval):

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

file_1 = bucket.file "path/to/my-file-1.ext",
                     generation: 1490390259479000, skip_lookup: true
file_2 = bucket.file "path/to/my-file-2.ext",
                     generation: 1490310974144000, skip_lookup: true

new_file = bucket.compose [file_1, file_2], "path/to/new-file.ext"
```

### #cors

```ruby
def cors() { |cors| ... } -> Bucket::Cors
```
Returns the current CORS configuration for a static website served
from the bucket.


The return value is a frozen (unmodifiable) array of hashes containing
the attributes specified for the Bucket resource field
[cors](https://cloud.google.com/storage/docs/json_api/v1/buckets#cors).

<br />

This method also accepts a block for updating the bucket's CORS rules.
See [Cors](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Cors.md.txt "Google::Cloud::Storage::Bucket::Cors (class)") for details.
**Yields**

- (cors) --- a block for setting CORS rules
**Yield Parameter**

- **cors** ([Bucket::Cors](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Cors.md.txt)) --- the object accepting CORS rules
**Returns**

- ([Bucket::Cors](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Cors.md.txt)) --- The frozen builder object.
**Examples**

Retrieving the bucket's CORS rules.

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
bucket.cors.size #=> 2
rule = bucket.cors.first
rule.origin #=> ["http://example.org"]
rule.methods #=> ["GET","POST","DELETE"]
rule.headers #=> ["X-My-Custom-Header"]
rule.max_age #=> 3600
```

Updating the bucket's CORS rules inside a block.

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-todo-app"

bucket.update do |b|
  b.cors do |c|
    c.add_rule ["http://example.org", "https://example.org"],
               "*",
               headers: ["X-My-Custom-Header"],
               max_age: 3600
  end
end
```

### #create_file

```ruby
def create_file(file, path = nil, acl: nil, cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, custom_time: nil, checksum: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, encryption_key: nil, kms_key: nil, temporary_hold: nil, event_based_hold: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil) -> Google::Cloud::Storage::File
```
**Aliases**

- [#upload_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_upload_file_instance_)
- [#new_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_new_file_instance_)
Creates a new [File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt "Google::Cloud::Storage::File (class)") object by providing a path to a local file (or
any File-like object such as StringIO) to upload, along with the path
at which to store it in the bucket.

##### Customer-supplied encryption keys


<br />

By default, Google Cloud Storage manages server-side encryption keys
on your behalf. However, a [customer-supplied encryption key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
can be provided with the `encryption_key` option. If given, the same
key must be provided to subsequently download or copy the file. If you
use customer-supplied encryption keys, you must securely manage your
keys and ensure that they are not lost. Also, please note that file
metadata is not encrypted, with the exception of the CRC32C checksum
and MD5 hash. The names of files and buckets are also not encrypted,
and you can read or update the metadata of an encrypted file without
providing the encryption key.
**Parameters**

- **file** (String, [::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)) --- Path of the file on the filesystem to upload. Can be an File object, or File-like object such as StringIO. (If the object does not have path, a `path` argument must be also be provided.)
- **path** (String) --- Path to store the file in Google Cloud Storage.
- **acl** (String) *(defaults to: nil)* ---

  A predefined set of access controls to apply to
  this file.

  Acceptable values are:
  - `auth`, `auth_read`, `authenticated`, `authenticated_read`, `authenticatedRead` - File owner gets OWNER access, and allAuthenticatedUsers get READER access.
  - `owner_full`, `bucketOwnerFullControl` - File owner gets OWNER access, and project team owners get OWNER access.
  - `owner_read`, `bucketOwnerRead` - File owner gets OWNER access, and project team owners get READER access.
  - `private` - File owner gets OWNER access.
  - `project_private`, `projectPrivate` - File owner gets OWNER access, and project team members get access according to their roles.
  - `public`, `public_read`, `publicRead` - File owner gets OWNER access, and allUsers get READER access.
- **cache_control** (String) *(defaults to: nil)* --- The [Cache-Control](https://tools.ietf.org/html/rfc7234#section-5.2) response header to be returned when the file is downloaded.
- **content_disposition** (String) *(defaults to: nil)* --- The [Content-Disposition](https://tools.ietf.org/html/rfc6266) response header to be returned when the file is downloaded.
- **content_encoding** (String) *(defaults to: nil)* --- The [Content-Encoding](https://tools.ietf.org/html/rfc7231#section-3.1.2.2) response header to be returned when the file is downloaded. For example, `content_encoding: "gzip"` can indicate to clients that the uploaded data is gzip-compressed. However, there is no check to guarantee the specified `Content-Encoding` has actually been applied to the file data, and incorrectly specifying the file's encoding could lead to unintended behavior on subsequent download requests.
- **content_language** (String) *(defaults to: nil)* --- The [Content-Language](http://tools.ietf.org/html/bcp47) response header to be returned when the file is downloaded.
- **content_type** (String) *(defaults to: nil)* --- The [Content-Type](https://tools.ietf.org/html/rfc2616#section-14.17) response header to be returned when the file is downloaded.
- **custom_time** (DateTime) *(defaults to: nil)* --- A custom time specified by the user for the file. Once set, custom_time can't be unset, and it can only be changed to a time in the future. If custom_time must be unset, you must either perform a rewrite operation, or upload the data again and create a new file.
- **checksum** (Symbol, nil, Boolean) *(defaults to: nil)* ---

  The type of checksum for the client to
  automatically calculate and send with the create request to verify
  the integrity of the object. If provided, Cloud Storage will only
  create the file if the value calculated by the client matches the
  value calculated by the service.

  Acceptable values are:
  - `true` \[Boolean\] - Calculate and provide a checksum using the CRC32c hash.
  - `false` \[Boolean\] - Do not calculate or provide a checksum.
  - `md5` - Calculate and provide a checksum using the MD5 hash.
  - `crc32c` - Calculate and provide a checksum using the CRC32c hash.
  - `all` - Calculate and provide checksums for all available verifications. Optional. The default is `crc32c`. Do not provide if also providing a corresponding `crc32c` or `md5` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **crc32c** (String) *(defaults to: nil)* --- The CRC32c checksum of the file data, as described in [RFC 4960, Appendix
  B](http://tools.ietf.org/html/rfc4960#appendix-B). If provided, Cloud Storage will only create the file if the value matches the value calculated by the service. Do not provide if also providing a `checksum: :crc32c` or `checksum: :all` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **md5** (String) *(defaults to: nil)* --- The MD5 hash of the file data. If provided, Cloud Storage will only create the file if the value matches the value calculated by the service. Do not provide if also providing a `checksum: :md5` or `checksum: :all` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **metadata** (Hash) *(defaults to: nil)* --- A hash of custom, user-provided web-safe keys and arbitrary string values that will returned with requests for the file as "x-goog-meta-" response headers.
- **storage_class** (Symbol, String) *(defaults to: nil)* --- Storage class of the file. Determines how the file is stored and determines the SLA and the cost of storage. Accepted values include `:standard`, `:nearline`, `:coldline`, and `:archive`, as well as the equivalent strings returned by [#storage_class](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_storage_class_instance_ "Google::Cloud::Storage::Bucket#storage_class (method)"). `:multi_regional`, `:regional`, and `durable_reduced_availability` are accepted legacy storage classes. For more information, see [Storage
  Classes](https://cloud.google.com/storage/docs/storage-classes) and [Per-Object Storage
  Class](https://cloud.google.com/storage/docs/per-object-storage-class). The default value is the default storage class for the bucket.
- **encryption_key** (String) *(defaults to: nil)* --- Optional. A customer-supplied, AES-256 encryption key that will be used to encrypt the file. Do not provide if `kms_key` is used.
- **kms_key** (String) *(defaults to: nil)* --- Optional. Resource name of the Cloud KMS key, of the form `projects/my-prj/locations/kr-loc/keyRings/my-kr/cryptoKeys/my-key`, that will be used to encrypt the file. The KMS key ring must use the same location as the bucket.The Service Account associated with your project requires access to this encryption key. Do not provide if `encryption_key` is used.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_generation_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation does not match the given value. If no live file exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration matches the given value.
- **if_metageneration_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration does not match the given value.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt))
**Raises**

- (ArgumentError)
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.create_file "path/to/local.file.ext"
```

Specifying a destination path:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext"
```

Providing a customer-supplied encryption key:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

# Key generation shown for example purposes only. Write your own.
cipher = OpenSSL::Cipher.new "aes-256-cfb"
cipher.encrypt
key = cipher.random_key

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext",
                   encryption_key: key

# Store your key and hash securely for later use.
file = bucket.file "destination/path/file.ext",
                   encryption_key: key
```

Providing a customer-managed Cloud KMS encryption key:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

# KMS key ring must use the same location as the bucket.
kms_key_name = "projects/a/locations/b/keyRings/c/cryptoKeys/d"

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext",
                   kms_key: kms_key_name

file = bucket.file "destination/path/file.ext"
file.kms_key #=> kms_key_name
```

Create a file with gzip-encoded data.

```ruby
require "zlib"
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

gz = StringIO.new ""
z = Zlib::GzipWriter.new gz
z.write "Hello world!"
z.close
data = StringIO.new gz.string

bucket = storage.bucket "my-bucket"

bucket.create_file data, "path/to/gzipped.txt",
                   content_encoding: "gzip"

file = bucket.file "path/to/gzipped.txt"

# The downloaded data is decompressed by default.
file.download "path/to/downloaded/hello.txt"

# The downloaded data remains compressed with skip_decompress.
file.download "path/to/downloaded/gzipped.txt",
              skip_decompress: true
```

### #create_notification

```ruby
def create_notification(topic, custom_attrs: nil, event_types: nil, prefix: nil, payload: nil) -> Google::Cloud::Storage::Notification
```
**Aliases**

- [#new_notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_new_notification_instance_)
Creates a new Pub/Sub notification subscription for the bucket.
**Parameters**

- **topic** (String) --- The name of the Cloud PubSub topic to which the notification subscription will publish.
- **custom_attrs** (Hash(String =\> String)) *(defaults to: nil)* --- The custom attributes for the notification. An optional list of additional attributes to attach to each Cloud Pub/Sub message published for the notification subscription.
- **event_types** (Symbol, String, Array\<Symbol, String\>) *(defaults to: nil)* ---

  The event
  types for the notification subscription. If provided, messages will
  only be sent for the listed event types. If empty, messages will be
  sent for all event types.

  Acceptable values are:
  - `:finalize` - Sent when a new object (or a new generation of an existing object) is successfully created in the bucket. This includes copying or rewriting an existing object. A failed upload does not trigger this event.
  - `:update` - Sent when the metadata of an existing object changes.
  - `:delete` - Sent when an object has been permanently deleted. This includes objects that are overwritten or are deleted as part of the bucket's lifecycle configuration. For buckets with object versioning enabled, this is not sent when an object is archived (see `OBJECT_ARCHIVE`), even if archival occurs via the [File#delete](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_delete_instance_ "Google::Cloud::Storage::File#delete (method)") method.
  - `:archive` - Only sent when the bucket has enabled object versioning. This event indicates that the live version of an object has become an archived version, either because it was archived or because it was overwritten by the upload of an object of the same name.
- **prefix** (String) *(defaults to: nil)* --- The file name prefix for the notification subscription. If provided, the notification will only be applied to file names that begin with this prefix.
- **payload** (Symbol, String, Boolean) *(defaults to: nil)* --- The desired content of the Pub/Sub message payload. Acceptable values are:


  - `:json` or `true` - The Pub/Sub message payload will be a UTF-8 string containing the [resource
    representation](https://cloud.google.com/storage/docs/json_api/v1/objects#resource-representations) of the file's metadata.
  - `:none` or `false` - No payload is included with the notification.

  The default value is `:json`.
**Returns**

- ([Google::Cloud::Storage::Notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Notification.md.txt))
**Example**

```ruby
require "google/cloud/pubsub"
require "google/cloud/storage"

pubsub = Google::Cloud::Pubsub.new
storage = Google::Cloud::Storage.new

topic = pubsub.create_topic "my-topic"
topic.policy do |p|
  p.add "roles/pubsub.publisher",
        "serviceAccount:#{storage.service_account_email}"
end

bucket = storage.bucket "my-bucket"

notification = bucket.create_notification topic.name
```

### #created_at

```ruby
def created_at() -> DateTime
```
Creation time of the bucket.
**Returns**

- (DateTime)

### #customer_managed_encryption_enforcement_config

```ruby
def customer_managed_encryption_enforcement_config() -> Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig, nil
```
The bucket's encryption configuration for customer-managed encryption keys.
This configuration defines the
default encryption behavior for the bucket and its files, and it can be used to enforce encryption requirements for the bucket.
For more information, see [Bucket encryption](https://docs.cloud.google.com/storage/docs/encryption.md.txt).
**Returns**

- (Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig, nil) --- The bucket's encryption configuration, or `nil` if no encryption configuration has been set.
**Example**

```ruby
require "google/cloud/storage"
#
storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
bucket.customer_managed_encryption_enforcement_config 
==> #<Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig:0x00007f3b1c102e90 @restriction_mode="NotRestricted">
The value for `restriction_mode` can be either "NotRestricted" or "FullyRestricted"
```

### #customer_managed_encryption_enforcement_config=

```ruby
def customer_managed_encryption_enforcement_config=(new_customer_managed_encryption_enforcement_config) -> Hash, Google::Apis::StorageV1::Bucket::Encryption
```
Sets the customer-managed encryption enforcement configuration for the bucket.
**Parameter**

- **new_customer_managed_encryption_enforcement_config** (Hash, nil) ---

  The configuration hash for encryption enforcement.
  - `:restriction_mode` (String) - Can be "NotRestricted" or "FullyRestricted". Pass `nil` to clear the current configuration.
**Returns**

- (Hash, Google::Apis::StorageV1::Bucket::Encryption) --- The updated configuration.
**Raises**

- (Google::Cloud::Error) --- If the update fails due to permissions or invalid arguments.
**Examples**

Enforcing Customer-Managed Encryption

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

# Set restriction mode to FullyRestricted
restricted_config = { restriction_mode: "FullyRestricted" }
bucket.customer_managed_encryption_enforcement_config = restricted_config
```

Setting via Request Object (Google API Client)

```ruby
require "google/apis/storage_v1"

enforcement_config = { restriction_mode: "FullyRestricted" }

request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
  customer_managed_encryption_enforcement_config: enforcement_config
)
bucket.customer_managed_encryption_enforcement_config = request_obj
```

### #customer_supplied_encryption_enforcement_config

```ruby
def customer_supplied_encryption_enforcement_config() -> Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig, nil
```
The bucket's encryption configuration for customer-supplied encryption keys.
For more information, see [Bucket encryption](https://docs.cloud.google.com/storage/docs/encryption.md.txt).
The bucket's encryption configuration, or `nil` if no encryption configuration has been set.
**Returns**

- (Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig, nil)
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.customer_supplied_encryption_enforcement_config 
  ==> #<Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig:0x00007f3b1c102e90 @restriction_mode="NotRestricted">
The value for `restriction_mode` can be either "NotRestricted" or "FullyRestricted".
```

### #customer_supplied_encryption_enforcement_config=

```ruby
def customer_supplied_encryption_enforcement_config=(new_customer_supplied_encryption_enforcement_config) -> Hash, Google::Apis::StorageV1::Bucket::Encryption
```
Sets the bucket's encryption configuration for customer-supplied encryption that will be used to protect files.
**Parameter**

- **new_customer_supplied_encryption_enforcement_config** (Hash, nil) ---

  The configuration hash for encryption enforcement.
  - `:restriction_mode` (String) - Can be "NotRestricted" or "FullyRestricted". Pass `nil` to clear the current configuration.
**Returns**

- (Hash, Google::Apis::StorageV1::Bucket::Encryption) --- The updated configuration.
**Raises**

- (Google::Cloud::Error) --- If the update fails due to permissions or invalid arguments.
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
restricted_config = { restriction_mode: "FullyRestricted" }
bucket.customer_supplied_encryption_enforcement_config = restricted_config
```

Setting via Request Object (Google API Client)

```ruby
require "google/apis/storage_v1"

enforcement_config = { restriction_mode: "FullyRestricted" }

request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
  customer_supplied_encryption_enforcement_config: enforcement_config
)
bucket.customer_supplied_encryption_enforcement_config = request_obj
```

### #data_locations

```ruby
def data_locations()
```
<https://cloud.google.com/storage/docs/locations>

### #default_acl

```ruby
def default_acl() -> Bucket::DefaultAcl
```
The [DefaultAcl](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-DefaultAcl.md.txt "Google::Cloud::Storage::Bucket::DefaultAcl (class)") instance used to control access to the
bucket's files.


<br />

A bucket's files have owners, writers, and readers. Permissions can be
granted to an individual user's email address, a group's email
address, as well as many predefined lists.
**Returns**

- ([Bucket::DefaultAcl](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-DefaultAcl.md.txt))
**Examples**

Grant access to a user by prepending `"user-"` to an email:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"

email = "heidi@example.net"
bucket.default_acl.add_reader "user-#{email}"
```

Grant access to a group by prepending `"group-"` to an email

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"

email = "authors@example.net"
bucket.default_acl.add_reader "group-#{email}"
```

Or, grant access via a predefined permissions list:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"

bucket.default_acl.public!
```

### #default_event_based_hold=

```ruby
def default_event_based_hold=(new_default_event_based_hold)
```
Updates the default event-based hold field for the bucket. This field
controls the initial state of the `event_based_hold` field for
newly-created files in the bucket.


See [File#event_based_hold?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_event_based_hold__instance_ "Google::Cloud::Storage::File#event_based_hold? (method)") and [File#set_event_based_hold!](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_set_event_based_hold__instance_ "Google::Cloud::Storage::File#set_event_based_hold! (method)").

<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **new_default_event_based_hold** (Boolean) --- The default event-based hold field for the bucket.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.update do |b|
  b.retention_period = 2592000 # 30 days in seconds
  b.default_event_based_hold = true
end

file = bucket.create_file "path/to/local.file.ext"
file.event_based_hold? # true
file.delete # raises Google::Cloud::PermissionDeniedError
file.release_event_based_hold!

# The end of the retention period is calculated from the time that
# the event-based hold was released.
file.retention_expires_at
```

### #default_event_based_hold?

```ruby
def default_event_based_hold?() -> Boolean
```
Whether the `event_based_hold` field for newly-created files in the
bucket will be initially set to `true`. See
[#default_event_based_hold=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_default_event_based_hold__instance_ "Google::Cloud::Storage::Bucket#default_event_based_hold= (method)"), [File#event_based_hold?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_event_based_hold__instance_ "Google::Cloud::Storage::File#event_based_hold? (method)") and
[File#set_event_based_hold!](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_set_event_based_hold__instance_ "Google::Cloud::Storage::File#set_event_based_hold! (method)").
**Returns**

- (Boolean) --- Returns `true` if the `event_based_hold` field for newly-created files in the bucket will be initially set to `true`, otherwise `false`.

### #default_kms_key

```ruby
def default_kms_key() -> String, nil
```
The Cloud KMS encryption key that will be used to protect files.
For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`
**Returns**

- (String, nil) --- A Cloud KMS encryption key, or `nil` if none has been configured.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

# KMS key ring must use the same location as the bucket.
kms_key_name = "projects/a/locations/b/keyRings/c/cryptoKeys/d"
bucket.default_kms_key = kms_key_name

bucket.default_kms_key #=> kms_key_name
```

### #default_kms_key=

```ruby
def default_kms_key=(new_default_kms_key)
```
Set the Cloud KMS encryption key that will be used to protect files.
For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **new_default_kms_key** (String, nil) --- New Cloud KMS key name, or `nil` to delete the Cloud KMS encryption key.
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

# KMS key ring must use the same location as the bucket.
kms_key_name = "projects/a/locations/b/keyRings/c/cryptoKeys/d"

bucket.default_kms_key = kms_key_name
```

Delete the default Cloud KMS encryption key:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.default_kms_key = nil
```

### #delete

```ruby
def delete(if_metageneration_match: nil, if_metageneration_not_match: nil) -> Boolean
```
Permanently deletes the bucket.
The bucket must be empty before it can be deleted.


<br />

The API call to delete the bucket may be retried under certain
conditions. See [Google::Cloud#storage](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud.md.txt#Google__Cloud_storage_instance_ "Google::Cloud#storage (method)") to control this behavior.
**Parameters**

- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the bucket's current metageneration matches the given value.
- **if_metageneration_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the bucket's current metageneration does not match the given value.
**Returns**

- (Boolean) --- Returns `true` if the bucket was deleted.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
bucket.delete
```

### #exists?

```ruby
def exists?() -> Boolean
```
Determines whether the bucket exists in the Storage service.
**Returns**

- (Boolean) --- true if the bucket exists in the Storage service.

### #file

```ruby
def file(path, generation: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, skip_lookup: nil, encryption_key: nil, soft_deleted: nil) -> Google::Cloud::Storage::File, nil
```
**Aliases**

- [#find_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_find_file_instance_)
Retrieves a file matching the path.


<br />

If a [customer-supplied encryption
key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
was used with [#create_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_create_file_instance_ "Google::Cloud::Storage::Bucket#create_file (method)"), the `encryption_key` option must be
provided or else the file's CRC32C checksum and MD5 hash will not be
returned.
**Parameters**

- **path** (String) --- Name (path) of the file.
- **generation** (Integer) *(defaults to: nil)* --- When present, selects a specific revision of this object. Default is the latest version.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_generation_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation does not match the given value. If no live file exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration matches the given value.
- **if_metageneration_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration does not match the given value.
- **skip_lookup** (Boolean) *(defaults to: nil)* --- Optionally create a Bucket object without verifying the bucket resource exists on the Storage service. Calls made on this object will raise errors if the bucket resource does not exist. Default is `false`.
- **encryption_key** (String) *(defaults to: nil)* --- Optional. The customer-supplied, AES-256 encryption key used to encrypt the file, if one was provided to [#create_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_create_file_instance_ "Google::Cloud::Storage::Bucket#create_file (method)"). (Not used if `skip_lookup` is also set.)
- **soft_deleted** (Boolean) *(defaults to: nil)* --- Optional. If true, only soft-deleted object versions will be listed. The default is false.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt), nil) --- Returns nil if file does not exist
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

file = bucket.file "path/to/my-file.ext"
puts file.name
```

### #files

```ruby
def files(prefix: nil, delimiter: nil, token: nil, max: nil, versions: nil, match_glob: nil, include_folders_as_prefixes: nil, soft_deleted: nil, filter: nil) -> Array<Google::Cloud::Storage::File>
```
**Aliases**

- [#find_files](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_find_files_instance_)
Retrieves a list of files matching the criteria.


List any object that has a context with the specified key attached
filter = "contexts.\&quot;KEY\&quot;:\*";

List any object that has a context with the specified key attached and value attached
filter = "contexts.\&quot;keyA\&quot;=\&quot;valueA\&quot;"

List any object that does not have a context with the specified key attached
filter = "-contexts.\&quot;KEY\&quot;:\*";

List any object that has a context with the specified key and value attached
filter = "contexts.\&quot;KEY\&quot;=\&quot;VALUE\&quot;";

<br />

List any object that does not have a context with the specified key and value attached
filter = "-contexts.\&quot;KEY\&quot;=\&quot;VALUE\&quot;";
**Parameters**

- **prefix** (String) *(defaults to: nil)* --- Filter results to files whose names begin with this prefix.
- **delimiter** (String) *(defaults to: nil)* --- Returns results in a directory-like mode. `items` 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.
- **token** (String) *(defaults to: nil)* --- A previously-returned page token representing part of the larger set of results to view.
- **match_glob** (String) *(defaults to: nil)* --- A glob pattern used to filter results returned in items (e.g. `foo*bar`). The string value must be UTF-8 encoded. See: https://cloud.google.com/storage/docs/json_api/v1/objects/list#list-object-glob
- **max** (Integer) *(defaults to: nil)* --- Maximum number of items plus prefixes to return. As duplicate prefixes are omitted, fewer total results may be returned than requested. The default value of this parameter is 1,000 items.
- **versions** (Boolean) *(defaults to: nil)* --- If `true`, lists all versions of an object as distinct results. The default is `false`. For more information, see [Object Versioning](https://cloud.google.com/storage/docs/object-versioning).
- **include_folders_as_prefixes** (Boolean) *(defaults to: nil)* --- If `true`, will also include folders and managed folders, besides objects, in the returned prefixes. Only applicable if delimiter is set to '/'.
- **soft_deleted** (Boolean) *(defaults to: nil)* --- If true, only soft-deleted object versions will be listed. The default is false.
- **filter** (String) *(defaults to: nil)* --- An optional string for filtering listed objects. Supported fields: contexts If delimiter is set, the returned prefixes are exempt from this filter
**Returns**

- (Array\<[Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)\>) --- (See [File::List](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File-List.md.txt "Google::Cloud::Storage::File::List (class)"))
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
files = bucket.files
files.each do |file|
  puts file.name
end
```

Retrieve all files: (See [File::List#all](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File-List.md.txt#Google__Cloud__Storage__File__List_all_instance_ "Google::Cloud::Storage::File::List#all (method)"))

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
files = bucket.files
files.all do |file|
  puts file.name
end
```

Filter files by context:

```ruby
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
files = bucket.files filter: "contexts.\"myKey\"=\"myValue\""
files.each do |file|
  puts file.name
end
```

### #find_file

```ruby
def find_file(path, generation: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, skip_lookup: nil, encryption_key: nil, soft_deleted: nil) -> Google::Cloud::Storage::File, nil
```
**Alias Of** : [#file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_file_instance_) Retrieves a file matching the path.


<br />

If a [customer-supplied encryption
key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
was used with [#create_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_create_file_instance_ "Google::Cloud::Storage::Bucket#create_file (method)"), the `encryption_key` option must be
provided or else the file's CRC32C checksum and MD5 hash will not be
returned.
**Parameters**

- **path** (String) --- Name (path) of the file.
- **generation** (Integer) *(defaults to: nil)* --- When present, selects a specific revision of this object. Default is the latest version.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_generation_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation does not match the given value. If no live file exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration matches the given value.
- **if_metageneration_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration does not match the given value.
- **skip_lookup** (Boolean) *(defaults to: nil)* --- Optionally create a Bucket object without verifying the bucket resource exists on the Storage service. Calls made on this object will raise errors if the bucket resource does not exist. Default is `false`.
- **encryption_key** (String) *(defaults to: nil)* --- Optional. The customer-supplied, AES-256 encryption key used to encrypt the file, if one was provided to [#create_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_create_file_instance_ "Google::Cloud::Storage::Bucket#create_file (method)"). (Not used if `skip_lookup` is also set.)
- **soft_deleted** (Boolean) *(defaults to: nil)* --- Optional. If true, only soft-deleted object versions will be listed. The default is false.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt), nil) --- Returns nil if file does not exist
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

file = bucket.file "path/to/my-file.ext"
puts file.name
```

### #find_files

```ruby
def find_files(prefix: nil, delimiter: nil, token: nil, max: nil, versions: nil, match_glob: nil, include_folders_as_prefixes: nil, soft_deleted: nil, filter: nil) -> Array<Google::Cloud::Storage::File>
```
**Alias Of** : [#files](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_files_instance_) Retrieves a list of files matching the criteria.


List any object that has a context with the specified key attached
filter = "contexts.\&quot;KEY\&quot;:\*";

List any object that has a context with the specified key attached and value attached
filter = "contexts.\&quot;keyA\&quot;=\&quot;valueA\&quot;"

List any object that does not have a context with the specified key attached
filter = "-contexts.\&quot;KEY\&quot;:\*";

List any object that has a context with the specified key and value attached
filter = "contexts.\&quot;KEY\&quot;=\&quot;VALUE\&quot;";

<br />

List any object that does not have a context with the specified key and value attached
filter = "-contexts.\&quot;KEY\&quot;=\&quot;VALUE\&quot;";
**Parameters**

- **prefix** (String) *(defaults to: nil)* --- Filter results to files whose names begin with this prefix.
- **delimiter** (String) *(defaults to: nil)* --- Returns results in a directory-like mode. `items` 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.
- **token** (String) *(defaults to: nil)* --- A previously-returned page token representing part of the larger set of results to view.
- **match_glob** (String) *(defaults to: nil)* --- A glob pattern used to filter results returned in items (e.g. `foo*bar`). The string value must be UTF-8 encoded. See: https://cloud.google.com/storage/docs/json_api/v1/objects/list#list-object-glob
- **max** (Integer) *(defaults to: nil)* --- Maximum number of items plus prefixes to return. As duplicate prefixes are omitted, fewer total results may be returned than requested. The default value of this parameter is 1,000 items.
- **versions** (Boolean) *(defaults to: nil)* --- If `true`, lists all versions of an object as distinct results. The default is `false`. For more information, see [Object Versioning](https://cloud.google.com/storage/docs/object-versioning).
- **include_folders_as_prefixes** (Boolean) *(defaults to: nil)* --- If `true`, will also include folders and managed folders, besides objects, in the returned prefixes. Only applicable if delimiter is set to '/'.
- **soft_deleted** (Boolean) *(defaults to: nil)* --- If true, only soft-deleted object versions will be listed. The default is false.
- **filter** (String) *(defaults to: nil)* --- An optional string for filtering listed objects. Supported fields: contexts If delimiter is set, the returned prefixes are exempt from this filter
**Returns**

- (Array\<[Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)\>) --- (See [File::List](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File-List.md.txt "Google::Cloud::Storage::File::List (class)"))
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
files = bucket.files
files.each do |file|
  puts file.name
end
```

Retrieve all files: (See [File::List#all](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File-List.md.txt#Google__Cloud__Storage__File__List_all_instance_ "Google::Cloud::Storage::File::List#all (method)"))

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
files = bucket.files
files.all do |file|
  puts file.name
end
```

Filter files by context:

```ruby
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
files = bucket.files filter: "contexts.\"myKey\"=\"myValue\""
files.each do |file|
  puts file.name
end
```

### #find_notification

```ruby
def find_notification(id) -> Google::Cloud::Storage::Notification, nil
```
**Alias Of** : [#notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_notification_instance_) Retrieves a Pub/Sub notification subscription for the bucket.
**Parameter**

- **id** (String) --- The Notification ID.
**Returns**

- ([Google::Cloud::Storage::Notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Notification.md.txt), nil) --- Returns nil if the notification does not exist
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

notification = bucket.notification "1"
puts notification.id
```

### #find_notifications

```ruby
def find_notifications() -> Array<Google::Cloud::Storage::Notification>
```
**Alias Of** : [#notifications](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_notifications_instance_) Retrieves the entire list of Pub/Sub notification subscriptions for
the bucket.
**Returns**

- (Array\<[Google::Cloud::Storage::Notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Notification.md.txt)\>)
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
notifications = bucket.notifications
notifications.each do |notification|
  puts notification.id
end
```

### #generate_signed_post_policy_v4

```ruby
def generate_signed_post_policy_v4(path, issuer: nil, client_email: nil, signing_key: nil, private_key: nil, signer: nil, expires: nil, fields: nil, conditions: nil, scheme: "https", virtual_hosted_style: nil, bucket_bound_hostname: nil) -> PostObject
```
Generate a `PostObject` that includes the fields and URL to
upload objects via HTML forms. The resulting `PostObject` is
based on a policy document created from the method arguments.
This policy provides authorization to ensure that the HTML
form can upload files into the bucket. See [Signatures -
Policy document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).


Generating a `PostObject` requires service account credentials,
either by connecting with a service account when calling
[Google::Cloud.storage](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud.md.txt#Google__Cloud_storage_class_ "Google::Cloud.storage (method)"), or by passing in the service account
`issuer` and `signing_key` values. Although the private key can
be passed as a string for convenience, creating and storing
an instance of `OpenSSL::PKey::RSA` is more efficient
when making multiple calls to `generate_signed_post_policy_v4`.

<br />

A [SignedUrlUnavailable](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-SignedUrlUnavailable.md.txt "Google::Cloud::Storage::SignedUrlUnavailable (class)") is raised if the service account credentials
are missing. Service account credentials are acquired by following the
steps in [Service Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
**Parameters**

- **path** (String) --- Path to the file in Google Cloud Storage.
- **issuer** (String) *(defaults to: nil)* --- Service Account's Client Email.
- **client_email** (String) *(defaults to: nil)* --- Service Account's Client Email.
- **signing_key** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.
- **private_key** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.
- **signer** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.


  When using this method in environments such as GAE Flexible Environment,
  GKE, or Cloud Functions where the private key is unavailable, it may be
  necessary to provide a Proc (or lambda) via the signer parameter. This
  Proc should return a signature created using a RPC call to the
  [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
  method as shown in the example below.
- **expires** (Integer) *(defaults to: nil)* --- The number of seconds until the URL expires. The default is 604800 (7 days).
- **fields** (Hash{String =\> String}) *(defaults to: nil)* --- User-supplied form fields such as `acl`, `cache-control`, `success_action_status`, and `success_action_redirect`. Optional. See [Upload an object with HTML forms - Form
  fields](https://cloud.google.com/storage/docs/xml-api/post-object-forms#form_fields).
- **conditions** (Array\<Hash{String =\> String}\|Array\<String\>\>) *(defaults to: nil)* --- An array of policy conditions that every upload must satisfy. For example: `[["eq", "$Content-Type", "image/jpeg"]]`. Optional. See [Signatures - Policy
  document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).
- **scheme** (String) *(defaults to: "https")* --- The URL scheme. The default value is `HTTPS`.
- **virtual_hosted_style** (Boolean) *(defaults to: nil)* --- Whether to use a virtual hosted-style hostname, which adds the bucket into the host portion of the URI rather than the path, e.g. `https://mybucket.storage.googleapis.com/...`. The default value of `false` uses the form of `https://storage.googleapis.com/mybucket`.
- **bucket_bound_hostname** (String) *(defaults to: nil)* --- Use a bucket-bound hostname, which replaces the `storage.googleapis.com` host with the name of a `CNAME` bucket, e.g. a bucket named `gcs-subdomain.my.domain.tld`, or a Google Cloud Load Balancer which routes to a bucket you own, e.g. `my-load-balancer-domain.tld`.
**Returns**

- ([PostObject](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PostObject.md.txt)) --- An object containing the URL, fields, and values needed to upload files via HTML forms.
**Raises**

- ([SignedUrlUnavailable](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-SignedUrlUnavailable.md.txt)) --- If the service account credentials are missing. Service account credentials are acquired by following the steps in [Service
  Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"

conditions = [["starts-with", "$acl","public"]]
post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
                                             expires:    10,
                                             conditions: conditions

post.url #=> "https://storage.googleapis.com/my-todo-app/"
post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
post.fields["policy"] #=> "ABC...XYZ"
post.fields["x-goog-algorithm"] #=> "GOOG4-RSA-SHA256"
post.fields["x-goog-credential"] #=> "cred@pid.iam.gserviceaccount.com/20200123/auto/storage/goog4_request"
post.fields["x-goog-date"] #=> "20200128T000000Z"
post.fields["x-goog-signature"] #=> "4893a0e...cd82"
```

Using Cloud IAMCredentials signBlob to create the signature:

```ruby
require "google/cloud/storage"
require "google/apis/iamcredentials_v1"
require "googleauth"

# Issuer is the service account email that the Signed URL will be signed with
# and any permission granted in the Signed URL must be granted to the
# Google Service Account.
issuer = "service-account@project-id.iam.gserviceaccount.com"

# Create a lambda that accepts the string_to_sign
signer = lambda do |string_to_sign|
  IAMCredentials = Google::Apis::IamcredentialsV1
  iam_client = IAMCredentials::IAMCredentialsService.new

  # Get the environment configured authorization
  scopes = ["https://www.googleapis.com/auth/iam"]
  iam_client.authorization = Google::Auth.get_application_default scopes

  request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
    payload: string_to_sign
  )
  resource = "projects/-/serviceAccounts/#{issuer}"
  response = iam_client.sign_service_account_blob resource, request
  response.signed_blob
end

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
conditions = [["starts-with", "$acl","public"]]
post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
                                             expires:    10,
                                             conditions: conditions,
                                             issuer:     issuer,
                                             signer:     signer

post.url #=> "https://storage.googleapis.com/my-todo-app/"
post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
post.fields["policy"] #=> "ABC...XYZ"
post.fields["x-goog-algorithm"] #=> "GOOG4-RSA-SHA256"
post.fields["x-goog-credential"] #=> "cred@pid.iam.gserviceaccount.com/20200123/auto/storage/goog4_request"
post.fields["x-goog-date"] #=> "20200128T000000Z"
post.fields["x-goog-signature"] #=> "4893a0e...cd82"
```

### #generation

```ruby
def generation()
```
Fetches generation of the bucket
**Example**

```ruby
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
generation= bucket.generation
```

### #google_managed_encryption_enforcement_config

```ruby
def google_managed_encryption_enforcement_config() -> Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig, nil
```
The bucket's encryption configuration for google-managed encryption keys.
This configuration defines the
default encryption behavior for the bucket and its files, and it can be used to enforce encryption
requirements for the bucket.
For more information, see [Bucket encryption](https://docs.cloud.google.com/storage/docs/encryption.md.txt).
The bucket's encryption configuration, or `nil` if no encryption configuration has been set.
**Returns**

- (Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig, nil)
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
bucket.google_managed_encryption_enforcement_config
==> #<Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig:0x00007f3b1c102e90 @restriction_mode="NotRestricted">
The value for `restriction_mode` can be either "NotRestricted" or "FullyRestricted".
```

### #google_managed_encryption_enforcement_config=

```ruby
def google_managed_encryption_enforcement_config=(new_google_managed_encryption_enforcement_config) -> Hash, Google::Apis::StorageV1::Bucket::Encryption
```
Sets the google-managed encryption enforcement configuration for the bucket.
**Parameter**

- **new_google_managed_encryption_enforcement_config** (Hash, nil) ---

  The configuration hash for encryption enforcement.
  - `:restriction_mode` (String) - Can be "NotRestricted" or "FullyRestricted". Pass `nil` to clear the current configuration.
**Returns**

- (Hash, Google::Apis::StorageV1::Bucket::Encryption) --- The updated configuration.
**Raises**

- (Google::Cloud::Error) --- If the update fails due to permissions or invalid arguments.
**Examples**

Enforcing Customer-Managed Encryption

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"
# Set restriction mode to FullyRestricted
restricted_config = { restriction_mode: "FullyRestricted" }
bucket.google_managed_encryption_enforcement_config = restricted_config
```

Setting via Request Object (Google API Client)

```ruby
require "google/apis/storage_v1"

enforcement_config = { restriction_mode: "FullyRestricted" }

request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
  google_managed_encryption_enforcement_config: enforcement_config
)
bucket.google_managed_encryption_enforcement_config = request_obj
```

### #hard_delete_time

```ruby
def hard_delete_time()
```
Fetches hard_delete_time of a soft deleted bucket
**Example**

```ruby
bucket.hard_delete_time
```

### #hierarchical_namespace

```ruby
def hierarchical_namespace() -> Google::Apis::StorageV1::Bucket::HierarchicalNamespace
```
The bucket's hierarchical namespace (Folders) configuration.
This value can be modified by calling [#hierarchical_namespace=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_hierarchical_namespace__instance_ "Google::Cloud::Storage::Bucket#hierarchical_namespace= (method)").
**Returns**

- (Google::Apis::StorageV1::Bucket::HierarchicalNamespace)
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.hierarchical_namespace
```

### #hierarchical_namespace=

```ruby
def hierarchical_namespace=(new_hierarchical_namespace)
```
Sets the value of Hierarchical Namespace (Folders) for the bucket.
This can only be enabled at bucket create time. If this is enabled,
Uniform Bucket-Level Access must also be enabled.
This value can be queried by calling [#hierarchical_namespace](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_hierarchical_namespace_instance_ "Google::Cloud::Storage::Bucket#hierarchical_namespace (method)").
**Parameter**

- **new_hierarchical_namespace** (Google::Apis::StorageV1::Bucket::HierarchicalNamespace, Hash(String =\> String)) --- The bucket's new Hierarchical Namespace Configuration.
**Examples**

Enabled Hierarchical Namespace using HierarchicalNamespace class:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

hierarchical_namespace = Google::Apis::StorageV1::Bucket::HierarchicalNamespace.new
hierarchical_namespace.enabled = true

bucket.hierarchical_namespace = hierarchical_namespace
```

Disable Hierarchical Namespace using Hash:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

hierarchical_namespace = { enabled: false }
bucket.hierarchical_namespace = hierarchical_namespace
```

### #id

```ruby
def id() -> String
```
The ID of the bucket.
**Returns**

- (String)

### #kind

```ruby
def kind() -> String
```
The kind of item this is.
For buckets, this is always `storage#bucket`.
**Returns**

- (String)

### #labels

```ruby
def labels() -> Hash(String => String)
```
A hash of user-provided labels. The hash is frozen and changes are not
allowed.
**Returns**

- (Hash(String =\> String))

### #labels=

```ruby
def labels=(labels)
```
Updates the hash of user-provided labels.


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **labels** (Hash(String =\> String)) --- The user-provided labels.

### #lifecycle

```ruby
def lifecycle() { |lifecycle| ... } -> Bucket::Lifecycle
```
Returns the current Object Lifecycle Management rules configuration
for the bucket.


<br />

This method also accepts a block for updating the bucket's Object
Lifecycle Management rules. See [Lifecycle](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Lifecycle.md.txt "Google::Cloud::Storage::Bucket::Lifecycle (class)") for details.
**Yields**

- (lifecycle) --- a block for setting Object Lifecycle Management rules
**Yield Parameter**

- **lifecycle** ([Bucket::Lifecycle](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Lifecycle.md.txt)) --- the object accepting Object Lifecycle Management rules
**Returns**

- ([Bucket::Lifecycle](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Lifecycle.md.txt)) --- The frozen builder object.
**Examples**

Retrieving a bucket's lifecycle management rules.

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.lifecycle.size #=> 2
rule = bucket.lifecycle.first
rule.action #=> "SetStorageClass"
rule.storage_class #=> "COLDLINE"
rule.age #=> 10
rule.matches_storage_class #=> ["STANDARD", "NEARLINE"]
```

Updating the bucket's lifecycle management rules in a block.

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.update do |b|
  b.lifecycle do |l|
    # Remove the last rule from the array
    l.pop
    # Remove rules with the given condition
    l.delete_if do |r|
      r.matches_storage_class.include? "NEARLINE"
    end
    # Update rules
    l.each do |r|
      r.age = 90 if r.action == "Delete"
    end
    # Add a rule
    l.add_set_storage_class_rule "COLDLINE", age: 10
  end
end
```

### #location

```ruby
def location() -> String
```
The location of the bucket.
Object data for objects in the bucket resides in physical
storage within this region. Defaults to US.
See the developer's guide for the authoritative list.
**Returns**

- (String)

### #location_type

```ruby
def location_type() -> String
```
The bucket's location type. Location type defines the geographic
placement of the bucket's data and affects cost, performance, and
availability. There are three possible values:

- `region` - Lowest latency within a single region
- `multi-region` - Highest availability across largest area
- `dual-region` - High availability and low latency across 2 regions
**Returns**

- (String) --- The location type code: "region", "multi-region", or "dual-region"

### #lock_retention_policy!

```ruby
def lock_retention_policy!() -> Boolean
```
PERMANENTLY locks the retention policy (see [#retention_period=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_period__instance_ "Google::Cloud::Storage::Bucket#retention_period= (method)")) on
the bucket if one exists. The policy is transitioned to a locked state
in which its duration cannot be reduced.


Locked policies can be extended in duration by setting
[#retention_period=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_period__instance_ "Google::Cloud::Storage::Bucket#retention_period= (method)") to a higher value. Such an extension is
permanent, and it cannot later be reduced. The extended duration will
apply retroactively to all files currently in the bucket.

This method also [creates a
lien](https://cloud.google.com/resource-manager/reference/rest/v1/liens/create)
on the `resourcemanager.projects.delete` permission for the project
containing the bucket.

<br />

The bucket's metageneration value is required for the lock policy API
call. Attempting to call this method on a bucket that was loaded with
the `skip_lookup: true` option will result in an error.
**Returns**

- (Boolean) --- Returns `true` if the lock operation is successful.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.retention_period = 2592000 # 30 days in seconds
bucket.lock_retention_policy!
bucket.retention_policy_locked? # true

file = bucket.create_file "path/to/local.file.ext"
file.delete # raises Google::Cloud::PermissionDeniedError

# Locked policies can be extended in duration
bucket.retention_period = 7776000 # 90 days in seconds
```

### #logging_bucket

```ruby
def logging_bucket() -> String
```
The destination bucket name for the bucket's logs.
**Returns**

- (String)

### #logging_bucket=

```ruby
def logging_bucket=(logging_bucket)
```
Updates the destination bucket for the bucket's logs.


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **logging_bucket** (String) --- The bucket to hold the logging output

### #logging_prefix

```ruby
def logging_prefix() -> String
```
The logging object prefix for the bucket's logs. For more information,
**Returns**

- (String)

### #logging_prefix=

```ruby
def logging_prefix=(logging_prefix)
```
Updates the logging object prefix. This prefix will be used to create
log object names for the bucket. It can be at most 900 characters and
must be a [valid object
name](https://cloud.google.com/storage/docs/bucket-naming#objectnames).
By default, the object prefix is the name of the bucket for which the
logs are enabled.


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **logging_prefix** (String) --- The logging object prefix.

### #metageneration

```ruby
def metageneration() -> Integer
```
The metadata generation of the bucket.
**Returns**

- (Integer) --- The metageneration.

### #move_file

```ruby
def move_file(source_file, destination_file, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, if_source_generation_match: nil, if_source_generation_not_match: nil, if_source_metageneration_match: nil, if_source_metageneration_not_match: nil, user_project: nil, fields: nil, quota_user: nil, user_ip: nil, options: {})
```
Moves File from source to destination path within the bucket.
This Operation is being performed at server side
If the destination path includes non-existent parent folders, they will be created.
**Parameters**

- **source_file** (String) --- The file name in existing bucket
- **destination_file** (String) --- The new filename to be created on bucket
**Example**

```ruby
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket  = storage.bucket bucket_name, skip_lookup: true
bucket.move_file source_file_name, destination_file_name
```

### #name

```ruby
def name() -> String
```
The name of the bucket.
**Returns**

- (String)

### #new_file

```ruby
def new_file(file, path = nil, acl: nil, cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, custom_time: nil, checksum: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, encryption_key: nil, kms_key: nil, temporary_hold: nil, event_based_hold: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil) -> Google::Cloud::Storage::File
```
**Alias Of** : [#create_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_create_file_instance_) Creates a new [File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt "Google::Cloud::Storage::File (class)") object by providing a path to a local file (or
any File-like object such as StringIO) to upload, along with the path
at which to store it in the bucket.

##### Customer-supplied encryption keys


<br />

By default, Google Cloud Storage manages server-side encryption keys
on your behalf. However, a [customer-supplied encryption key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
can be provided with the `encryption_key` option. If given, the same
key must be provided to subsequently download or copy the file. If you
use customer-supplied encryption keys, you must securely manage your
keys and ensure that they are not lost. Also, please note that file
metadata is not encrypted, with the exception of the CRC32C checksum
and MD5 hash. The names of files and buckets are also not encrypted,
and you can read or update the metadata of an encrypted file without
providing the encryption key.
**Parameters**

- **file** (String, [::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)) --- Path of the file on the filesystem to upload. Can be an File object, or File-like object such as StringIO. (If the object does not have path, a `path` argument must be also be provided.)
- **path** (String) --- Path to store the file in Google Cloud Storage.
- **acl** (String) *(defaults to: nil)* ---

  A predefined set of access controls to apply to
  this file.

  Acceptable values are:
  - `auth`, `auth_read`, `authenticated`, `authenticated_read`, `authenticatedRead` - File owner gets OWNER access, and allAuthenticatedUsers get READER access.
  - `owner_full`, `bucketOwnerFullControl` - File owner gets OWNER access, and project team owners get OWNER access.
  - `owner_read`, `bucketOwnerRead` - File owner gets OWNER access, and project team owners get READER access.
  - `private` - File owner gets OWNER access.
  - `project_private`, `projectPrivate` - File owner gets OWNER access, and project team members get access according to their roles.
  - `public`, `public_read`, `publicRead` - File owner gets OWNER access, and allUsers get READER access.
- **cache_control** (String) *(defaults to: nil)* --- The [Cache-Control](https://tools.ietf.org/html/rfc7234#section-5.2) response header to be returned when the file is downloaded.
- **content_disposition** (String) *(defaults to: nil)* --- The [Content-Disposition](https://tools.ietf.org/html/rfc6266) response header to be returned when the file is downloaded.
- **content_encoding** (String) *(defaults to: nil)* --- The [Content-Encoding](https://tools.ietf.org/html/rfc7231#section-3.1.2.2) response header to be returned when the file is downloaded. For example, `content_encoding: "gzip"` can indicate to clients that the uploaded data is gzip-compressed. However, there is no check to guarantee the specified `Content-Encoding` has actually been applied to the file data, and incorrectly specifying the file's encoding could lead to unintended behavior on subsequent download requests.
- **content_language** (String) *(defaults to: nil)* --- The [Content-Language](http://tools.ietf.org/html/bcp47) response header to be returned when the file is downloaded.
- **content_type** (String) *(defaults to: nil)* --- The [Content-Type](https://tools.ietf.org/html/rfc2616#section-14.17) response header to be returned when the file is downloaded.
- **custom_time** (DateTime) *(defaults to: nil)* --- A custom time specified by the user for the file. Once set, custom_time can't be unset, and it can only be changed to a time in the future. If custom_time must be unset, you must either perform a rewrite operation, or upload the data again and create a new file.
- **checksum** (Symbol, nil, Boolean) *(defaults to: nil)* ---

  The type of checksum for the client to
  automatically calculate and send with the create request to verify
  the integrity of the object. If provided, Cloud Storage will only
  create the file if the value calculated by the client matches the
  value calculated by the service.

  Acceptable values are:
  - `true` \[Boolean\] - Calculate and provide a checksum using the CRC32c hash.
  - `false` \[Boolean\] - Do not calculate or provide a checksum.
  - `md5` - Calculate and provide a checksum using the MD5 hash.
  - `crc32c` - Calculate and provide a checksum using the CRC32c hash.
  - `all` - Calculate and provide checksums for all available verifications. Optional. The default is `crc32c`. Do not provide if also providing a corresponding `crc32c` or `md5` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **crc32c** (String) *(defaults to: nil)* --- The CRC32c checksum of the file data, as described in [RFC 4960, Appendix
  B](http://tools.ietf.org/html/rfc4960#appendix-B). If provided, Cloud Storage will only create the file if the value matches the value calculated by the service. Do not provide if also providing a `checksum: :crc32c` or `checksum: :all` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **md5** (String) *(defaults to: nil)* --- The MD5 hash of the file data. If provided, Cloud Storage will only create the file if the value matches the value calculated by the service. Do not provide if also providing a `checksum: :md5` or `checksum: :all` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **metadata** (Hash) *(defaults to: nil)* --- A hash of custom, user-provided web-safe keys and arbitrary string values that will returned with requests for the file as "x-goog-meta-" response headers.
- **storage_class** (Symbol, String) *(defaults to: nil)* --- Storage class of the file. Determines how the file is stored and determines the SLA and the cost of storage. Accepted values include `:standard`, `:nearline`, `:coldline`, and `:archive`, as well as the equivalent strings returned by [#storage_class](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_storage_class_instance_ "Google::Cloud::Storage::Bucket#storage_class (method)"). `:multi_regional`, `:regional`, and `durable_reduced_availability` are accepted legacy storage classes. For more information, see [Storage
  Classes](https://cloud.google.com/storage/docs/storage-classes) and [Per-Object Storage
  Class](https://cloud.google.com/storage/docs/per-object-storage-class). The default value is the default storage class for the bucket.
- **encryption_key** (String) *(defaults to: nil)* --- Optional. A customer-supplied, AES-256 encryption key that will be used to encrypt the file. Do not provide if `kms_key` is used.
- **kms_key** (String) *(defaults to: nil)* --- Optional. Resource name of the Cloud KMS key, of the form `projects/my-prj/locations/kr-loc/keyRings/my-kr/cryptoKeys/my-key`, that will be used to encrypt the file. The KMS key ring must use the same location as the bucket.The Service Account associated with your project requires access to this encryption key. Do not provide if `encryption_key` is used.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_generation_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation does not match the given value. If no live file exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration matches the given value.
- **if_metageneration_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration does not match the given value.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt))
**Raises**

- (ArgumentError)
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.create_file "path/to/local.file.ext"
```

Specifying a destination path:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext"
```

Providing a customer-supplied encryption key:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

# Key generation shown for example purposes only. Write your own.
cipher = OpenSSL::Cipher.new "aes-256-cfb"
cipher.encrypt
key = cipher.random_key

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext",
                   encryption_key: key

# Store your key and hash securely for later use.
file = bucket.file "destination/path/file.ext",
                   encryption_key: key
```

Providing a customer-managed Cloud KMS encryption key:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

# KMS key ring must use the same location as the bucket.
kms_key_name = "projects/a/locations/b/keyRings/c/cryptoKeys/d"

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext",
                   kms_key: kms_key_name

file = bucket.file "destination/path/file.ext"
file.kms_key #=> kms_key_name
```

Create a file with gzip-encoded data.

```ruby
require "zlib"
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

gz = StringIO.new ""
z = Zlib::GzipWriter.new gz
z.write "Hello world!"
z.close
data = StringIO.new gz.string

bucket = storage.bucket "my-bucket"

bucket.create_file data, "path/to/gzipped.txt",
                   content_encoding: "gzip"

file = bucket.file "path/to/gzipped.txt"

# The downloaded data is decompressed by default.
file.download "path/to/downloaded/hello.txt"

# The downloaded data remains compressed with skip_decompress.
file.download "path/to/downloaded/gzipped.txt",
              skip_decompress: true
```

### #new_notification

```ruby
def new_notification(topic, custom_attrs: nil, event_types: nil, prefix: nil, payload: nil) -> Google::Cloud::Storage::Notification
```
**Alias Of** : [#create_notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_create_notification_instance_) Creates a new Pub/Sub notification subscription for the bucket.
**Parameters**

- **topic** (String) --- The name of the Cloud PubSub topic to which the notification subscription will publish.
- **custom_attrs** (Hash(String =\> String)) *(defaults to: nil)* --- The custom attributes for the notification. An optional list of additional attributes to attach to each Cloud Pub/Sub message published for the notification subscription.
- **event_types** (Symbol, String, Array\<Symbol, String\>) *(defaults to: nil)* ---

  The event
  types for the notification subscription. If provided, messages will
  only be sent for the listed event types. If empty, messages will be
  sent for all event types.

  Acceptable values are:
  - `:finalize` - Sent when a new object (or a new generation of an existing object) is successfully created in the bucket. This includes copying or rewriting an existing object. A failed upload does not trigger this event.
  - `:update` - Sent when the metadata of an existing object changes.
  - `:delete` - Sent when an object has been permanently deleted. This includes objects that are overwritten or are deleted as part of the bucket's lifecycle configuration. For buckets with object versioning enabled, this is not sent when an object is archived (see `OBJECT_ARCHIVE`), even if archival occurs via the [File#delete](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_delete_instance_ "Google::Cloud::Storage::File#delete (method)") method.
  - `:archive` - Only sent when the bucket has enabled object versioning. This event indicates that the live version of an object has become an archived version, either because it was archived or because it was overwritten by the upload of an object of the same name.
- **prefix** (String) *(defaults to: nil)* --- The file name prefix for the notification subscription. If provided, the notification will only be applied to file names that begin with this prefix.
- **payload** (Symbol, String, Boolean) *(defaults to: nil)* --- The desired content of the Pub/Sub message payload. Acceptable values are:


  - `:json` or `true` - The Pub/Sub message payload will be a UTF-8 string containing the [resource
    representation](https://cloud.google.com/storage/docs/json_api/v1/objects#resource-representations) of the file's metadata.
  - `:none` or `false` - No payload is included with the notification.

  The default value is `:json`.
**Returns**

- ([Google::Cloud::Storage::Notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Notification.md.txt))
**Example**

```ruby
require "google/cloud/pubsub"
require "google/cloud/storage"

pubsub = Google::Cloud::Pubsub.new
storage = Google::Cloud::Storage.new

topic = pubsub.create_topic "my-topic"
topic.policy do |p|
  p.add "roles/pubsub.publisher",
        "serviceAccount:#{storage.service_account_email}"
end

bucket = storage.bucket "my-bucket"

notification = bucket.create_notification topic.name
```

### #notification

```ruby
def notification(id) -> Google::Cloud::Storage::Notification, nil
```
**Aliases**

- [#find_notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_find_notification_instance_)
Retrieves a Pub/Sub notification subscription for the bucket.
**Parameter**

- **id** (String) --- The Notification ID.
**Returns**

- ([Google::Cloud::Storage::Notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Notification.md.txt), nil) --- Returns nil if the notification does not exist
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

notification = bucket.notification "1"
puts notification.id
```

### #notifications

```ruby
def notifications() -> Array<Google::Cloud::Storage::Notification>
```
**Aliases**

- [#find_notifications](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_find_notifications_instance_)
Retrieves the entire list of Pub/Sub notification subscriptions for
the bucket.
**Returns**

- (Array\<[Google::Cloud::Storage::Notification](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Notification.md.txt)\>)
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"
notifications = bucket.notifications
notifications.each do |notification|
  puts notification.id
end
```

### #object_retention

```ruby
def object_retention() -> Google::Apis::StorageV1::Bucket::ObjectRetention
```
The object retention configuration of the bucket
**Returns**

- (Google::Apis::StorageV1::Bucket::ObjectRetention)

### #policy

```ruby
def policy(force: nil, requested_policy_version: nil) { |policy| ... } -> Policy
```
Gets and updates the [Cloud IAM](https://cloud.google.com/iam/) access
control policy for this bucket.
**Parameters**

- **force** (Boolean) *(defaults to: nil)* --- \[Deprecated\] Force the latest policy to be retrieved from the Storage service when `true`. Deprecated because the latest policy is now always retrieved. The default is `nil`.
- **requested_policy_version** (Integer) *(defaults to: nil)* ---

  The requested syntax schema
  version of the policy. Optional. If `1`, `nil`, or not provided, a
  [PolicyV1](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1.md.txt "Google::Cloud::Storage::PolicyV1 (class)") object is returned, which
  provides [PolicyV1#roles](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1.md.txt#Google__Cloud__Storage__PolicyV1_roles_instance_ "Google::Cloud::Storage::PolicyV1#roles (method)") and related
  helpers but does not provide a `bindings` method. If `3` is
  provided, a [PolicyV3](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3.md.txt "Google::Cloud::Storage::PolicyV3 (class)") object is returned,
  which provides [PolicyV3#bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3.md.txt#Google__Cloud__Storage__PolicyV3_bindings_instance_ "Google::Cloud::Storage::PolicyV3#bindings (method)") but does
  not provide a `roles` method or related helpers. A higher version
  indicates that the policy contains role bindings with the newer
  syntax schema that is unsupported by earlier versions.

  The following requested policy versions are valid:
  - 1 - The first version of Cloud IAM policy schema. Supports binding one role to one or more members. Does not support conditional bindings.
  - 3 - Introduces the condition field in the role binding, which further constrains the role binding via context-based and attribute-based rules. See [Understanding policies](https://cloud.google.com/iam/docs/policies) and [Overview of Cloud IAM Conditions](https://cloud.google.com/iam/docs/conditions-overview) for more information.
**Yields**

- (policy) --- A block for updating the policy. The latest policy will be read from the service and passed to the block. After the block completes, the modified policy will be written to the service.
**Yield Parameter**

- **policy** ([Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt)) --- the current Cloud IAM Policy for this bucket
**Returns**

- ([Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt)) --- the current Cloud IAM Policy for this bucket
**Examples**

Retrieving a Policy that is implicitly version 1:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy
policy.version # 1
puts policy.roles["roles/storage.objectViewer"]
```

Retrieving a version 3 Policy using `requested_policy_version`:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy requested_policy_version: 3
policy.version # 3
puts policy.bindings.find do |b|
  b[:role] == "roles/storage.objectViewer"
end
```

Updating a Policy that is implicitly version 1:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.policy do |p|
  p.version # the value is 1
  p.remove "roles/storage.admin", "user:owner@example.com"
  p.add "roles/storage.admin", "user:newowner@example.com"
  p.roles["roles/storage.objectViewer"] = ["allUsers"]
end
```

Updating a Policy from version 1 to version 3 by adding a condition:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true

bucket.policy requested_policy_version: 3 do |p|
  p.version # the value is 1
  p.version = 3 # Must be explicitly set to opt-in to support for conditions.

  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.insert({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```

Updating a version 3 Policy:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access? # true

bucket.policy requested_policy_version: 3 do |p|
  p.version = 3 # Must be explicitly set to opt-in to support for conditions.

  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.insert({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```

### #policy=

```ruby
def policy=(new_policy) -> Policy
```
**Alias Of** : [#update_policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_policy_instance_) Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
policy for this bucket. The policy should be read from [#policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_policy_instance_ "Google::Cloud::Storage::Bucket#policy (method)"). See
[Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt "Google::Cloud::Storage::Policy (class)") for an explanation of the
policy `etag` property and how to modify policies.


<br />

You can also update the policy by passing a block to [#policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_policy_instance_ "Google::Cloud::Storage::Bucket#policy (method)"), which
will call this method internally after the block completes.
**Parameter**

- **new_policy** ([Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt)) --- a new or modified Cloud IAM Policy for this bucket
**Returns**

- ([Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt)) --- The policy returned by the API update operation.
**Examples**

Updating a Policy that is implicitly version 1:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy
policy.version # 1
policy.remove "roles/storage.admin", "user:owner@example.com"
policy.add "roles/storage.admin", "user:newowner@example.com"
policy.roles["roles/storage.objectViewer"] = ["allUsers"]

policy = bucket.update_policy policy
```

Updating a Policy from version 1 to version 3 by adding a condition:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy requested_policy_version: 3
policy.version # 1
policy.version = 3

expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
policy.bindings.insert({
                        role: "roles/storage.admin",
                        members: ["user:owner@example.com"],
                        condition: {
                          title: "my-condition",
                          description: "description of condition",
                          expression: expr
                        }
                      })

policy = bucket.update_policy policy
```

Updating a version 3 Policy:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy requested_policy_version: 3
policy.version # 3 indicates an existing binding with a condition.

expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
policy.bindings.insert({
                        role: "roles/storage.admin",
                        members: ["user:owner@example.com"],
                        condition: {
                          title: "my-condition",
                          description: "description of condition",
                          expression: expr
                        }
                      })

policy = bucket.update_policy policy
```

### #policy_only=

```ruby
def policy_only=(new_policy_only)
```

### #policy_only?

```ruby
def policy_only?() -> Boolean
```
**Returns**

- (Boolean)

### #policy_only_locked_at

```ruby
def policy_only_locked_at()
```

### #post_object

```ruby
def post_object(path, policy: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil, signer: nil) -> PostObject
```
Generate a PostObject that includes the fields and URL to
upload objects via HTML forms.


Generating a PostObject requires service account credentials,
either by connecting with a service account when calling
[Google::Cloud.storage](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud.md.txt#Google__Cloud_storage_class_ "Google::Cloud.storage (method)"), or by passing in the service account
`issuer` and `signing_key` values. Although the private key can
be passed as a string for convenience, creating and storing
an instance of # `OpenSSL::PKey::RSA` is more efficient
when making multiple calls to `post_object`.

<br />

A [SignedUrlUnavailable](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-SignedUrlUnavailable.md.txt "Google::Cloud::Storage::SignedUrlUnavailable (class)") is raised if the service account credentials
are missing. Service account credentials are acquired by following the
steps in [Service Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
**Parameters**

- **path** (String) --- Path to the file in Google Cloud Storage.
- **policy** (Hash) *(defaults to: nil)* --- The security policy that describes what can and cannot be uploaded in the form. When provided, the PostObject fields will include a signature based on the JSON representation of this hash and the same policy in Base64 format.


  If you do not provide a security policy, requests are considered
  to be anonymous and will only work with buckets that have granted
  `WRITE` or `FULL_CONTROL` permission to anonymous users.
  See [Policy Document](https://cloud.google.com/storage/docs/xml-api/post-object#policydocument)
  for more information.
- **issuer** (String) *(defaults to: nil)* --- Service Account's Client Email.
- **client_email** (String) *(defaults to: nil)* --- Service Account's Client Email.
- **signing_key** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.
- **private_key** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.
- **signer** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.


  When using this method in environments such as GAE Flexible Environment,
  GKE, or Cloud Functions where the private key is unavailable, it may be
  necessary to provide a Proc (or lambda) via the signer parameter. This
  Proc should return a signature created using a RPC call to the
  [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
  method as shown in the example below.
**Returns**

- ([PostObject](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PostObject.md.txt)) --- An object containing the URL, fields, and values needed to upload files via HTML forms.
**Raises**

- ([SignedUrlUnavailable](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-SignedUrlUnavailable.md.txt)) --- If the service account credentials are missing. Service account credentials are acquired by following the steps in [Service Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
post = bucket.post_object "avatars/heidi/400x400.png"

post.url #=> "https://storage.googleapis.com"
post.fields[:key] #=> "my-todo-app/avatars/heidi/400x400.png"
post.fields[:GoogleAccessId] #=> "0123456789@gserviceaccount.com"
post.fields[:signature] #=> "ABC...XYZ="
post.fields[:policy] #=> "ABC...XYZ="
```

Using a policy to define the upload authorization:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

policy = {
  expiration: (Time.now + 3600).iso8601,
  conditions: [
    ["starts-with", "$key", ""],
    {acl: "bucket-owner-read"},
    {bucket: "travel-maps"},
    {success_action_redirect: "http://example.com/success.html"},
    ["eq", "$Content-Type", "image/jpeg"],
    ["content-length-range", 0, 1000000]
  ]
}

bucket = storage.bucket "my-todo-app"
post = bucket.post_object "avatars/heidi/400x400.png",
                           policy: policy

post.url #=> "https://storage.googleapis.com"
post.fields[:key] #=> "my-todo-app/avatars/heidi/400x400.png"
post.fields[:GoogleAccessId] #=> "0123456789@gserviceaccount.com"
post.fields[:signature] #=> "ABC...XYZ="
post.fields[:policy] #=> "ABC...XYZ="
```

Using the issuer and signing_key options:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
key = OpenSSL::PKey::RSA.new
post = bucket.post_object "avatars/heidi/400x400.png",
                          issuer: "service-account@gcloud.com",
                          signing_key: key

post.url #=> "https://storage.googleapis.com"
post.fields[:key] #=> "my-todo-app/avatars/heidi/400x400.png"
post.fields[:GoogleAccessId] #=> "0123456789@gserviceaccount.com"
post.fields[:signature] #=> "ABC...XYZ="
post.fields[:policy] #=> "ABC...XYZ="
```

Using Cloud IAMCredentials signBlob to create the signature:

```ruby
require "google/cloud/storage"
require "google/apis/iamcredentials_v1"
require "googleauth"

# Issuer is the service account email that the Signed URL will be signed with
# and any permission granted in the Signed URL must be granted to the
# Google Service Account.
issuer = "service-account@project-id.iam.gserviceaccount.com"

# Create a lambda that accepts the string_to_sign
signer = lambda do |string_to_sign|
  IAMCredentials = Google::Apis::IamcredentialsV1
  iam_client = IAMCredentials::IAMCredentialsService.new

  # Get the environment configured authorization
  scopes = ["https://www.googleapis.com/auth/iam"]
  iam_client.authorization = Google::Auth.get_application_default scopes

  request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
    payload: string_to_sign
  )
  resource = "projects/-/serviceAccounts/#{issuer}"
  response = iam_client.sign_service_account_blob resource, request
  response.signed_blob
end

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
post = bucket.post_object "avatars/heidi/400x400.png",
                          issuer: issuer,
                          signer: signer

post.url #=> "https://storage.googleapis.com"
post.fields[:key] #=> "my-todo-app/avatars/heidi/400x400.png"
post.fields[:GoogleAccessId] #=> "0123456789@gserviceaccount.com"
post.fields[:signature] #=> "ABC...XYZ="
post.fields[:policy] #=> "ABC...XYZ="
```

### #public_access_prevention

```ruby
def public_access_prevention() -> String, nil
```
The value for Public Access Prevention in the bucket's IAM configuration. Currently, `inherited` and
`enforced` are supported. When set to `enforced`, Public Access Prevention is enforced in the bucket's IAM
configuration. This value can be modified by calling [#public_access_prevention=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_public_access_prevention__instance_ "Google::Cloud::Storage::Bucket#public_access_prevention= (method)").
**Returns**

- (String, nil) --- Currently, `inherited` and `enforced` are supported. Returns `nil` if the bucket has no IAM configuration.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.public_access_prevention = :enforced
bucket.public_access_prevention #=> "enforced"
```

### #public_access_prevention=

```ruby
def public_access_prevention=(new_public_access_prevention)
```
Sets the value for Public Access Prevention in the bucket's IAM configuration. This value can be queried by
calling [#public_access_prevention](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_public_access_prevention_instance_ "Google::Cloud::Storage::Bucket#public_access_prevention (method)").
**Parameter**

- **new_public_access_prevention** (Symbol, String) --- The bucket's new Public Access Prevention configuration. Currently, `inherited` and `enforced` are supported. When set to `enforced`, Public Access Prevention is enforced in the bucket's IAM configuration.
**Examples**

Set Public Access Prevention to enforced:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.public_access_prevention = :enforced
bucket.public_access_prevention #=> "enforced"
```

Set Public Access Prevention to inherited:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.public_access_prevention = :inherited
bucket.public_access_prevention #=> "inherited"
```

### #public_access_prevention_enforced?

```ruby
def public_access_prevention_enforced?() -> Boolean
```
Whether the bucket's file IAM configuration enforces Public Access Prevention. The default is `false`. This
value can be modified by calling [#public_access_prevention=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_public_access_prevention__instance_ "Google::Cloud::Storage::Bucket#public_access_prevention= (method)").
**Returns**

- (Boolean) --- Returns `false` if the bucket has no IAM configuration or if Public Access Prevention is not `enforced` in the IAM configuration. Returns `true` if Public Access Prevention is `enforced` in the IAM configuration.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.public_access_prevention = :enforced
bucket.public_access_prevention_enforced? # true
```

### #public_access_prevention_inherited?

```ruby
def public_access_prevention_inherited?() -> Boolean
```
**Aliases**

- [#public_access_prevention_unspecified?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_public_access_prevention_unspecified?_instance_)
Whether the value for Public Access Prevention in the bucket's IAM configuration is `inherited`. The default
is `false`. This value can be modified by calling [#public_access_prevention=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_public_access_prevention__instance_ "Google::Cloud::Storage::Bucket#public_access_prevention= (method)").
**Returns**

- (Boolean) --- Returns `false` if the bucket has no IAM configuration or if Public Access Prevention is not `inherited` in the IAM configuration. Returns `true` if Public Access Prevention is `inherited` in the IAM configuration.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.public_access_prevention = :inherited
bucket.public_access_prevention_inherited? # true
```

### #public_access_prevention_unspecified?

```ruby
def public_access_prevention_unspecified?() -> Boolean
```
**Alias Of** : [#public_access_prevention_inherited?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_public_access_prevention_inherited?_instance_) Whether the value for Public Access Prevention in the bucket's IAM configuration is `inherited`. The default
is `false`. This value can be modified by calling [#public_access_prevention=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_public_access_prevention__instance_ "Google::Cloud::Storage::Bucket#public_access_prevention= (method)").
**Returns**

- (Boolean) --- Returns `false` if the bucket has no IAM configuration or if Public Access Prevention is not `inherited` in the IAM configuration. Returns `true` if Public Access Prevention is `inherited` in the IAM configuration.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.public_access_prevention = :inherited
bucket.public_access_prevention_inherited? # true
```

### #refresh!

```ruby
def refresh!()
```
**Alias Of** : [#reload!](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_reload!_instance_) Reloads the bucket with current data from the Storage service.

### #reload!

```ruby
def reload!()
```
**Aliases**

- [#refresh!](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_refresh!_instance_)
Reloads the bucket with current data from the Storage service.

### #requester_pays

```ruby
def requester_pays() -> Boolean, nil
```
**Aliases**

- [#requester_pays?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_requester_pays?_instance_)
Indicates that a client accessing the bucket or a file it contains
must assume the transit costs related to the access. The requester
must pass the `user_project` option to [Project#bucket](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_bucket_instance_ "Google::Cloud::Storage::Project#bucket (method)") and
[Project#buckets](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_buckets_instance_ "Google::Cloud::Storage::Project#buckets (method)") to indicate the project to which the access costs
should be billed.
**Returns**

- (Boolean, nil) --- Returns `true` if requester pays is enabled for the bucket.

### #requester_pays=

```ruby
def requester_pays=(new_requester_pays)
```
Enables requester pays for the bucket. If enabled, a client accessing
the bucket or a file it contains must assume the transit costs related
to the access. The requester must pass the `user_project` option to
[Project#bucket](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_bucket_instance_ "Google::Cloud::Storage::Project#bucket (method)") and [Project#buckets](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_buckets_instance_ "Google::Cloud::Storage::Project#buckets (method)") to indicate the project to
which the access costs should be billed.


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **new_requester_pays** (Boolean) --- When set to `true`, requester pays is enabled for the bucket.
**Example**

Enable requester pays for a bucket:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.requester_pays = true # API call
# Other projects must now provide `user_project` option when calling
# Project#bucket or Project#buckets to access this bucket.
```

### #requester_pays?

```ruby
def requester_pays?() -> Boolean, nil
```
**Alias Of** : [#requester_pays](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_requester_pays_instance_) Indicates that a client accessing the bucket or a file it contains
must assume the transit costs related to the access. The requester
must pass the `user_project` option to [Project#bucket](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_bucket_instance_ "Google::Cloud::Storage::Project#bucket (method)") and
[Project#buckets](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_buckets_instance_ "Google::Cloud::Storage::Project#buckets (method)") to indicate the project to which the access costs
should be billed.
**Returns**

- (Boolean, nil) --- Returns `true` if requester pays is enabled for the bucket.

### #restore_file

```ruby
def restore_file(file_path, generation, copy_source_acl: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, projection: nil, user_project: nil, fields: nil, options: {}) -> Google::Cloud::Storage::File
```
Restores a soft-deleted object.
**Parameters**

- **file_path** (String) --- Name of the file.
- **generation** (Fixnum) --- Selects a specific revision of this object.
- **copy_source_acl** (Boolean) *(defaults to: nil)* --- If true, copies the source file's ACL; otherwise, uses the bucket's default file ACL. The default is false.
- **if_generation_match** (Fixnum) *(defaults to: nil)* --- Makes the operation conditional on whether the file's one live generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_generation_not_match** (Fixnum) *(defaults to: nil)* --- Makes the operation conditional on whether none of the file's live generations match the given value. If no live file exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the file.
- **if_metageneration_match** (Fixnum) *(defaults to: nil)* --- Makes the operation conditional on whether the file's one live metageneration matches the given value.
- **if_metageneration_not_match** (Fixnum) *(defaults to: nil)* --- Makes the operation conditional on whether none of the object's live metagenerations match the given value.
- **projection** (String) *(defaults to: nil)* --- Set of properties to return. Defaults to full.
- **user_project** (String) *(defaults to: nil)* --- The project to be billed for this request. Required for Requester Pays buckets.
- **fields** (String) *(defaults to: nil)* --- Selector specifying which fields to include in a partial response.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt))
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.restore_file "path/of/file", <generation-of-the-file>
```

### #retention_effective_at

```ruby
def retention_effective_at() -> DateTime, nil
```
The time from which the retention policy was effective. Whenever a
retention policy is created or extended, GCS updates the effective
date of the policy. The effective date signals the date starting from
which objects were guaranteed to be retained for the full duration of
the policy.


<br />

This field is updated when the retention policy is created or
modified, including extension of a locked policy.
**Returns**

- (DateTime, nil) --- The effective date of the bucket's retention policy, if a policy exists.

### #retention_period

```ruby
def retention_period() -> Integer, nil
```
The period of time (in seconds) that files in the bucket must be
retained, and cannot be deleted, overwritten, or archived.
The value must be between 0 and 100 years (in seconds.)


<br />

See also: [#retention_period=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_period__instance_ "Google::Cloud::Storage::Bucket#retention_period= (method)"), [#retention_effective_at](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_effective_at_instance_ "Google::Cloud::Storage::Bucket#retention_effective_at (method)"), and
[#retention_policy_locked?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_policy_locked__instance_ "Google::Cloud::Storage::Bucket#retention_policy_locked? (method)").
**Returns**

- (Integer, nil) --- The retention period defined in seconds, if a retention policy exists for the bucket.

### #retention_period=

```ruby
def retention_period=(new_retention_period)
```
The period of time (in seconds) that files in the bucket must be
retained, and cannot be deleted, overwritten, or archived. Passing a
valid Integer value will add a new retention policy to the bucket
if none exists. Passing `nil` will remove the retention policy from
the bucket if it exists, unless the policy is locked.


Locked policies can be extended in duration by using this method
to set a higher value. Such an extension is permanent, and it cannot
later be reduced. The extended duration will apply retroactively to
all files currently in the bucket.

See also: [#lock_retention_policy!](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_lock_retention_policy__instance_ "Google::Cloud::Storage::Bucket#lock_retention_policy! (method)"), [#retention_period](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_period_instance_ "Google::Cloud::Storage::Bucket#retention_period (method)"),
[#retention_effective_at](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_effective_at_instance_ "Google::Cloud::Storage::Bucket#retention_effective_at (method)"), and [#retention_policy_locked?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_policy_locked__instance_ "Google::Cloud::Storage::Bucket#retention_policy_locked? (method)").

<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **new_retention_period** (Integer, nil) --- The retention period defined in seconds. The value must be between 0 and 100 years (in seconds), or `nil`.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.retention_period = 2592000 # 30 days in seconds

file = bucket.create_file "path/to/local.file.ext"
file.delete # raises Google::Cloud::PermissionDeniedError
```

### #retention_policy_locked?

```ruby
def retention_policy_locked?() -> Boolean
```
Whether the bucket's file retention policy is locked and its retention
period cannot be reduced. See [#retention_period=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_retention_period__instance_ "Google::Cloud::Storage::Bucket#retention_period= (method)") and
[#lock_retention_policy!](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_lock_retention_policy__instance_ "Google::Cloud::Storage::Bucket#lock_retention_policy! (method)").


<br />

This value can only be set to `true` by calling
[#lock_retention_policy!](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_lock_retention_policy__instance_ "Google::Cloud::Storage::Bucket#lock_retention_policy! (method)").
**Returns**

- (Boolean) --- Returns `false` if there is no retention policy or if the retention policy is unlocked and the retention period can be reduced. Returns `true` if the retention policy is locked and the retention period cannot be reduced.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.retention_period = 2592000 # 30 days in seconds
bucket.lock_retention_policy!
bucket.retention_policy_locked? # true

file = bucket.create_file "path/to/local.file.ext"
file.delete # raises Google::Cloud::PermissionDeniedError
```

### #rpo

```ruby
def rpo() -> String, nil
```
Recovery Point Objective (RPO) is another attribute of a bucket, it measures how long it takes for a set of
updates to be asynchronously copied to the other region.
Currently, `DEFAULT` and `ASYNC_TURBO` are supported. When set to `ASYNC_TURBO`, Turbo Replication is enabled
for a bucket. `DEFAULT` is used to reset rpo on an existing bucket with rpo set to `ASYNC_TURBO`.
This value can be modified by calling [#rpo=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_rpo__instance_ "Google::Cloud::Storage::Bucket#rpo= (method)").
**Returns**

- (String, nil) --- Currently, `DEFAULT` and `ASYNC_TURBO` are supported. Returns `nil` if the bucket has no RPO.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.rpo = :DEFAULT
bucket.rpo #=> "DEFAULT"
```

### #rpo=

```ruby
def rpo=(new_rpo)
```
Sets the value for Recovery Point Objective (RPO) in the bucket. This value can be queried by calling [#rpo](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_rpo_instance_ "Google::Cloud::Storage::Bucket#rpo (method)").
**Parameter**

- **new_rpo** (Symbol, String) --- The bucket's new Recovery Point Objective metadata. Currently, `DEFAULT` and `ASYNC_TURBO` are supported. When set to `ASYNC_TURBO`, Turbo Replication is enabled for a bucket.
**Examples**

Set RPO to DEFAULT:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.rpo = :DEFAULT
bucket.rpo #=> "DEFAULT"
```

Set RPO to ASYNC_TURBO:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.rpo = :ASYNC_TURBO
bucket.rpo #=> "ASYNC_TURBO"
```

### #signed_url

```ruby
def signed_url(path = nil, method: "GET", expires: nil, content_type: nil, content_md5: nil, headers: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil, signer: nil, query: nil, scheme: "HTTPS", virtual_hosted_style: nil, bucket_bound_hostname: nil, version: nil) -> String
```
Generates a signed URL. See [Signed
URLs](https://cloud.google.com/storage/docs/access-control/signed-urls)
for more information.


Generating a signed URL requires service account credentials, either
by connecting with a service account when calling
[Google::Cloud.storage](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud.md.txt#Google__Cloud_storage_class_ "Google::Cloud.storage (method)"), or by passing in the service account `issuer`
and `signing_key` values. Although the private key can be passed as a
string for convenience, creating and storing an instance of
`OpenSSL::PKey::RSA` is more efficient when making multiple calls to
`signed_url`.

<br />

A [SignedUrlUnavailable](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-SignedUrlUnavailable.md.txt "Google::Cloud::Storage::SignedUrlUnavailable (class)") is raised if the service account credentials
are missing. Service account credentials are acquired by following the
steps in [Service Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
**Parameters**

- **path** (String, nil) --- Path to the file in Google Cloud Storage, or `nil` to generate a URL for listing all files in the bucket.
- **method** (String) *(defaults to: "GET")* --- The HTTP verb to be used with the signed URL. Signed URLs can be used with `GET`, `HEAD`, `PUT`, and `DELETE` requests. Default is `GET`.
- **expires** (Integer) *(defaults to: nil)* --- The number of seconds until the URL expires. If the `version` is `:v2`, the default is 300 (5 minutes). If the `version` is `:v4`, the default is 604800 (7 days).
- **content_type** (String) *(defaults to: nil)* --- When provided, the client (browser) must send this value in the HTTP header. e.g. `text/plain`. This param is not used if the `version` is `:v4`.
- **content_md5** (String) *(defaults to: nil)* --- The MD5 digest value in base64. If you provide this in the string, the client (usually a browser) must provide this HTTP header with this same value in its request. This param is not used if the `version` is `:v4`.
- **headers** (Hash) *(defaults to: nil)* --- Google extension headers (custom HTTP headers that begin with `x-goog-`) that must be included in requests that use the signed URL.
- **issuer** (String) *(defaults to: nil)* --- Service Account's Client Email.
- **client_email** (String) *(defaults to: nil)* --- Service Account's Client Email.
- **signing_key** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.
- **private_key** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.
- **signer** (OpenSSL::PKey::RSA, String, Proc) *(defaults to: nil)* --- Service Account's Private Key or a Proc that accepts a single String parameter and returns a RSA SHA256 signature using a valid Google Service Account Private Key.


  When using this method in environments such as GAE Flexible Environment,
  GKE, or Cloud Functions where the private key is unavailable, it may be
  necessary to provide a Proc (or lambda) via the signer parameter. This
  Proc should return a signature created using a RPC call to the
  [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
  method as shown in the example below.
- **query** (Hash) *(defaults to: nil)* --- Query string parameters to include in the signed URL. The given parameters are not verified by the signature.


  Parameters such as `response-content-disposition` and
  `response-content-type` can alter the behavior of the response when
  using the URL, but only when the file resource is missing the
  corresponding values. (These values can be permanently set using
  [File#content_disposition=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_content_disposition__instance_ "Google::Cloud::Storage::File#content_disposition= (method)") and [File#content_type=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt#Google__Cloud__Storage__File_content_type__instance_ "Google::Cloud::Storage::File#content_type= (method)").)
- **scheme** (String) *(defaults to: "HTTPS")* --- The URL scheme. The default value is `HTTPS`.
- **virtual_hosted_style** (Boolean) *(defaults to: nil)* --- Whether to use a virtual hosted-style hostname, which adds the bucket into the host portion of the URI rather than the path, e.g. `https://mybucket.storage.googleapis.com/...`. For V4 signing, this also sets the `host` header in the canonicalized extension headers to the virtual hosted-style host, unless that header is supplied via the `headers` param. The default value of `false` uses the form of `https://storage.googleapis.com/mybucket`.
- **bucket_bound_hostname** (String) *(defaults to: nil)* --- Use a bucket-bound hostname, which replaces the `storage.googleapis.com` host with the name of a `CNAME` bucket, e.g. a bucket named `gcs-subdomain.my.domain.tld`, or a Google Cloud Load Balancer which routes to a bucket you own, e.g. `my-load-balancer-domain.tld`.
- **version** (Symbol, String) *(defaults to: nil)* --- The version of the signed credential to create. Must be one of `:v2` or `:v4`. The default value is `:v2`.
**Returns**

- (String) --- The signed URL.
**Raises**

- ([SignedUrlUnavailable](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-SignedUrlUnavailable.md.txt)) --- If the service account credentials are missing. Service account credentials are acquired by following the steps in [Service Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
shared_url = bucket.signed_url "avatars/heidi/400x400.png"
```

Using the `expires` and `version` options:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
shared_url = bucket.signed_url "avatars/heidi/400x400.png",
                               expires: 300, # 5 minutes from now
                               version: :v4
```

Using the `issuer` and `signing_key` options:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
key = OpenSSL::PKey::RSA.new "---BEGIN PRIVATE KEY---\n..."
shared_url = bucket.signed_url "avatars/heidi/400x400.png",
                               issuer: "service-account@gcloud.com",
                               signing_key: key
```

Using Cloud IAMCredentials signBlob to create the signature:

```ruby
require "google/cloud/storage"
require "google/apis/iamcredentials_v1"
require "googleauth"

# Issuer is the service account email that the Signed URL will be signed with
# and any permission granted in the Signed URL must be granted to the
# Google Service Account.
issuer = "service-account@project-id.iam.gserviceaccount.com"

# Create a lambda that accepts the string_to_sign
signer = lambda do |string_to_sign|
  IAMCredentials = Google::Apis::IamcredentialsV1
  iam_client = IAMCredentials::IAMCredentialsService.new

  # Get the environment configured authorization
  scopes = ["https://www.googleapis.com/auth/iam"]
  iam_client.authorization = Google::Auth.get_application_default scopes

  request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
    payload: string_to_sign
  )
  resource = "projects/-/serviceAccounts/#{issuer}"
  response = iam_client.sign_service_account_blob resource, request
  response.signed_blob
end

storage = Google::Cloud::Storage.new

bucket_name = "my-todo-app"
file_path = "avatars/heidi/400x400.png"
url = storage.signed_url bucket_name, file_path,
                         method: "GET", issuer: issuer,
                         signer: signer
```

Using the `headers` option:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
shared_url = bucket.signed_url "avatars/heidi/400x400.png",
                               headers: {
                                 "x-goog-acl" => "private",
                                 "x-goog-meta-foo" => "bar,baz"
                               }
```

Generating a signed URL for resumable upload:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
url = bucket.signed_url "avatars/heidi/400x400.png",
                        method: "POST",
                        content_type: "image/png",
                        headers: {
                          "x-goog-resumable" => "start"
                        }
# Send the `x-goog-resumable:start` header and the content type
# with the resumable upload POST request.
```

Omitting `path` for a URL to list all files in the bucket.

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
list_files_url = bucket.signed_url version: :v4
```

### #soft_delete_policy

```ruby
def soft_delete_policy() -> Google::Apis::StorageV1::Bucket::SoftDeletePolicy
```
The bucket's soft delete policy. If this policy is set, any deleted
objects will be soft-deleted according to the time specified in the
policy.
This value can be modified by calling [#soft_delete_policy=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_soft_delete_policy__instance_ "Google::Cloud::Storage::Bucket#soft_delete_policy= (method)").


<br />

days.
**Returns**

- (Google::Apis::StorageV1::Bucket::SoftDeletePolicy) --- The default retention policy is for 7
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.soft_delete_policy
```

### #soft_delete_policy=

```ruby
def soft_delete_policy=(new_soft_delete_policy)
```
Sets the value for Soft Delete Policy in the bucket. This value can
be queried by calling [#soft_delete_policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_soft_delete_policy_instance_ "Google::Cloud::Storage::Bucket#soft_delete_policy (method)").
**Parameter**

- **new_soft_delete_policy** (Google::Apis::StorageV1::Bucket::SoftDeletePolicy, Hash(String =\> String)) --- The bucket's new Soft Delete Policy.
**Examples**

Set Soft Delete Policy to 10 days using SoftDeletePolicy class:

```ruby
require "google/cloud/storage"
require "date"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

soft_delete_policy = Google::Apis::StorageV1::Bucket::SoftDeletePolicy.new
soft_delete_policy.retention_duration_seconds = 10*24*60*60

bucket.soft_delete_policy = soft_delete_policy
```

Set Soft Delete Policy to 5 days using Hash:

```ruby
require "google/cloud/storage"
require "date"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

soft_delete_policy = { retention_duration_seconds: 432000 }
bucket.soft_delete_policy = soft_delete_policy
```

### #soft_delete_time

```ruby
def soft_delete_time()
```
Fetches soft_delete_time of a soft deleted bucket
**Example**

```ruby
bucket.delete
bucket.soft_delete_time
```

### #storage_class

```ruby
def storage_class() -> String
```
The bucket's storage class. This defines how objects in the bucket are
stored and determines the SLA and the cost of storage. Values include
`STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`. `REGIONAL`,`MULTI_REGIONAL`,
and `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
classes.
**Returns**

- (String)

### #storage_class=

```ruby
def storage_class=(new_storage_class)
```
Updates the bucket's storage class. This defines how objects in the
bucket are stored and determines the SLA and the cost of storage.
Accepted values include `:standard`, `:nearline`, `:coldline`, and
`:archive`, as well as the equivalent strings returned by
[#storage_class](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_storage_class_instance_ "Google::Cloud::Storage::Bucket#storage_class (method)"). `:multi_regional`, `:regional`, and
`durable_reduced_availability` are accepted as legacy storage classes.
For more information, see [Storage
Classes](https://cloud.google.com/storage/docs/storage-classes).


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **new_storage_class** (Symbol, String) --- Storage class of the bucket.

### #test_permissions

```ruby
def test_permissions(*permissions) -> Array<String>
```
Tests the specified permissions against the [Cloud
IAM](https://cloud.google.com/iam/) access control policy.
**Parameter**

- **permissions** (String, Array\<String\>) --- The set of permissions against which to check access. Permissions must be of the format `storage.resource.capability`, where resource is one of `buckets` or `objects`.
**Returns**

- (Array\<String\>) --- The permissions held by the caller.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

permissions = bucket.test_permissions "storage.buckets.get",
                                      "storage.buckets.delete"
permissions.include? "storage.buckets.get"    #=> true
permissions.include? "storage.buckets.delete" #=> false
```

### #uniform_bucket_level_access=

```ruby
def uniform_bucket_level_access=(new_uniform_bucket_level_access)
```
Sets whether uniform bucket-level access is enabled for this bucket. When this is enabled, access to the
bucket will be configured through IAM, and legacy ACL policies will not work. When it is first enabled,
[#uniform_bucket_level_access_locked_at](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_uniform_bucket_level_access_locked_at_instance_ "Google::Cloud::Storage::Bucket#uniform_bucket_level_access_locked_at (method)") will be set by the API automatically. The uniform bucket-level access
can then be disabled until the time specified, after which it will become immutable and calls to change it
will fail. If uniform bucket-level access is enabled, calls to access legacy ACL information will fail.


Before enabling uniform bucket-level access please review [uniform bucket-level
access](https://cloud.google.com/storage/docs/uniform-bucket-level-access).

<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **new_uniform_bucket_level_access** (Boolean) --- When set to `true`, uniform bucket-level access is enabled in the bucket's IAM configuration.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true
bucket.uniform_bucket_level_access? # true

bucket.default_acl.public! # Google::Cloud::InvalidArgumentError

# The deadline for disabling uniform bucket-level access.
puts bucket.uniform_bucket_level_access_locked_at
```

### #uniform_bucket_level_access?

```ruby
def uniform_bucket_level_access?() -> Boolean
```
Whether the bucket's file IAM configuration enables uniform bucket-level access. The default is false. This
value can be modified by calling [#uniform_bucket_level_access=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_uniform_bucket_level_access__instance_ "Google::Cloud::Storage::Bucket#uniform_bucket_level_access= (method)").
**Returns**

- (Boolean) --- Returns `false` if the bucket has no IAM configuration or if uniform bucket-level access is not enabled in the IAM configuration. Returns `true` if uniform bucket-level access is enabled in the IAM configuration.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true
bucket.uniform_bucket_level_access? # true
```

### #uniform_bucket_level_access_locked_at

```ruby
def uniform_bucket_level_access_locked_at() -> DateTime, nil
```
The deadline time for disabling uniform bucket-level access by calling [#uniform_bucket_level_access=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_uniform_bucket_level_access__instance_ "Google::Cloud::Storage::Bucket#uniform_bucket_level_access= (method)").
After the locked time the uniform bucket-level access setting cannot be changed from true to false.
Corresponds to the property `locked_time`.
**Returns**

- (DateTime, nil) --- The deadline time for changing [#uniform_bucket_level_access=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_uniform_bucket_level_access__instance_ "Google::Cloud::Storage::Bucket#uniform_bucket_level_access= (method)") from true to false, or `nil` if [#uniform_bucket_level_access?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_uniform_bucket_level_access__instance_ "Google::Cloud::Storage::Bucket#uniform_bucket_level_access? (method)") is false.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true

# The deadline for disabling uniform bucket-level access.
puts bucket.uniform_bucket_level_access_locked_at
```

### #update

```ruby
def update(if_metageneration_match: nil, if_metageneration_not_match: nil)
```
Updates the bucket with changes made in the given block in a single
PATCH request. The following attributes may be set: [#cors](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_cors_instance_ "Google::Cloud::Storage::Bucket#cors (method)"),
[#logging_bucket=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_logging_bucket__instance_ "Google::Cloud::Storage::Bucket#logging_bucket= (method)"), [#logging_prefix=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_logging_prefix__instance_ "Google::Cloud::Storage::Bucket#logging_prefix= (method)"), [#versioning=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_versioning__instance_ "Google::Cloud::Storage::Bucket#versioning= (method)"),
[#website_main=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_website_main__instance_ "Google::Cloud::Storage::Bucket#website_main= (method)"), [#website_404=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_website_404__instance_ "Google::Cloud::Storage::Bucket#website_404= (method)"), and [#requester_pays=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_requester_pays__instance_ "Google::Cloud::Storage::Bucket#requester_pays= (method)").


<br />

In addition, the #cors configuration accessible in the block is
completely mutable and will be included in the request. (See
[Cors](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket-Cors.md.txt "Google::Cloud::Storage::Bucket::Cors (class)"))
**Parameters**

- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the bucket's current metageneration matches the given value.
- **if_metageneration_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the bucket's current metageneration does not match the given value.
**Yields**

- (bucket) --- a block yielding a delegate object for updating the file
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
bucket.update do |b|
  b.website_main = "index.html"
  b.website_404 = "not_found.html"
  b.cors[0].methods = ["GET","POST","DELETE"]
  b.cors[1].headers << "X-Another-Custom-Header"
end
```

New CORS rules can also be added in a nested block:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-todo-app"

bucket.update do |b|
  b.cors do |c|
    c.add_rule ["http://example.org", "https://example.org"],
               "*",
               headers: ["X-My-Custom-Header"],
               max_age: 300
  end
end
```

With a `if_metageneration_match` precondition:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-todo-app"
bucket.update if_metageneration_match: 6 do |b|
  b.website_main = "index.html"
end
```

### #update_autoclass

```ruby
def update_autoclass(autoclass_attributes)
```
Update method to update all attributes of autoclass of a bucket
It accepts params as a Hash of attributes in the following format:


    { enabled: true, terminal_storage_class: "ARCHIVE" }

<br />

terminal_storage_class field is optional. It defaults to `NEARLINE`.
Valid terminal_storage_class values are `NEARLINE` and `ARCHIVE`.
**Parameter**

- **autoclass_attributes** (Hash(String =\> String))

### #update_policy

```ruby
def update_policy(new_policy) -> Policy
```
**Aliases**

- [#policy=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_policy=_instance_)
Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
policy for this bucket. The policy should be read from [#policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_policy_instance_ "Google::Cloud::Storage::Bucket#policy (method)"). See
[Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt "Google::Cloud::Storage::Policy (class)") for an explanation of the
policy `etag` property and how to modify policies.


<br />

You can also update the policy by passing a block to [#policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_policy_instance_ "Google::Cloud::Storage::Bucket#policy (method)"), which
will call this method internally after the block completes.
**Parameter**

- **new_policy** ([Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt)) --- a new or modified Cloud IAM Policy for this bucket
**Returns**

- ([Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt)) --- The policy returned by the API update operation.
**Examples**

Updating a Policy that is implicitly version 1:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy
policy.version # 1
policy.remove "roles/storage.admin", "user:owner@example.com"
policy.add "roles/storage.admin", "user:newowner@example.com"
policy.roles["roles/storage.objectViewer"] = ["allUsers"]

policy = bucket.update_policy policy
```

Updating a Policy from version 1 to version 3 by adding a condition:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy requested_policy_version: 3
policy.version # 1
policy.version = 3

expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
policy.bindings.insert({
                        role: "roles/storage.admin",
                        members: ["user:owner@example.com"],
                        condition: {
                          title: "my-condition",
                          description: "description of condition",
                          expression: expr
                        }
                      })

policy = bucket.update_policy policy
```

Updating a version 3 Policy:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy requested_policy_version: 3
policy.version # 3 indicates an existing binding with a condition.

expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
policy.bindings.insert({
                        role: "roles/storage.admin",
                        members: ["user:owner@example.com"],
                        condition: {
                          title: "my-condition",
                          description: "description of condition",
                          expression: expr
                        }
                      })

policy = bucket.update_policy policy
```

### #upload_file

```ruby
def upload_file(file, path = nil, acl: nil, cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, custom_time: nil, checksum: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, encryption_key: nil, kms_key: nil, temporary_hold: nil, event_based_hold: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil) -> Google::Cloud::Storage::File
```
**Alias Of** : [#create_file](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_create_file_instance_) Creates a new [File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt "Google::Cloud::Storage::File (class)") object by providing a path to a local file (or
any File-like object such as StringIO) to upload, along with the path
at which to store it in the bucket.

##### Customer-supplied encryption keys


<br />

By default, Google Cloud Storage manages server-side encryption keys
on your behalf. However, a [customer-supplied encryption key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
can be provided with the `encryption_key` option. If given, the same
key must be provided to subsequently download or copy the file. If you
use customer-supplied encryption keys, you must securely manage your
keys and ensure that they are not lost. Also, please note that file
metadata is not encrypted, with the exception of the CRC32C checksum
and MD5 hash. The names of files and buckets are also not encrypted,
and you can read or update the metadata of an encrypted file without
providing the encryption key.
**Parameters**

- **file** (String, [::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt)) --- Path of the file on the filesystem to upload. Can be an File object, or File-like object such as StringIO. (If the object does not have path, a `path` argument must be also be provided.)
- **path** (String) --- Path to store the file in Google Cloud Storage.
- **acl** (String) *(defaults to: nil)* ---

  A predefined set of access controls to apply to
  this file.

  Acceptable values are:
  - `auth`, `auth_read`, `authenticated`, `authenticated_read`, `authenticatedRead` - File owner gets OWNER access, and allAuthenticatedUsers get READER access.
  - `owner_full`, `bucketOwnerFullControl` - File owner gets OWNER access, and project team owners get OWNER access.
  - `owner_read`, `bucketOwnerRead` - File owner gets OWNER access, and project team owners get READER access.
  - `private` - File owner gets OWNER access.
  - `project_private`, `projectPrivate` - File owner gets OWNER access, and project team members get access according to their roles.
  - `public`, `public_read`, `publicRead` - File owner gets OWNER access, and allUsers get READER access.
- **cache_control** (String) *(defaults to: nil)* --- The [Cache-Control](https://tools.ietf.org/html/rfc7234#section-5.2) response header to be returned when the file is downloaded.
- **content_disposition** (String) *(defaults to: nil)* --- The [Content-Disposition](https://tools.ietf.org/html/rfc6266) response header to be returned when the file is downloaded.
- **content_encoding** (String) *(defaults to: nil)* --- The [Content-Encoding](https://tools.ietf.org/html/rfc7231#section-3.1.2.2) response header to be returned when the file is downloaded. For example, `content_encoding: "gzip"` can indicate to clients that the uploaded data is gzip-compressed. However, there is no check to guarantee the specified `Content-Encoding` has actually been applied to the file data, and incorrectly specifying the file's encoding could lead to unintended behavior on subsequent download requests.
- **content_language** (String) *(defaults to: nil)* --- The [Content-Language](http://tools.ietf.org/html/bcp47) response header to be returned when the file is downloaded.
- **content_type** (String) *(defaults to: nil)* --- The [Content-Type](https://tools.ietf.org/html/rfc2616#section-14.17) response header to be returned when the file is downloaded.
- **custom_time** (DateTime) *(defaults to: nil)* --- A custom time specified by the user for the file. Once set, custom_time can't be unset, and it can only be changed to a time in the future. If custom_time must be unset, you must either perform a rewrite operation, or upload the data again and create a new file.
- **checksum** (Symbol, nil, Boolean) *(defaults to: nil)* ---

  The type of checksum for the client to
  automatically calculate and send with the create request to verify
  the integrity of the object. If provided, Cloud Storage will only
  create the file if the value calculated by the client matches the
  value calculated by the service.

  Acceptable values are:
  - `true` \[Boolean\] - Calculate and provide a checksum using the CRC32c hash.
  - `false` \[Boolean\] - Do not calculate or provide a checksum.
  - `md5` - Calculate and provide a checksum using the MD5 hash.
  - `crc32c` - Calculate and provide a checksum using the CRC32c hash.
  - `all` - Calculate and provide checksums for all available verifications. Optional. The default is `crc32c`. Do not provide if also providing a corresponding `crc32c` or `md5` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **crc32c** (String) *(defaults to: nil)* --- The CRC32c checksum of the file data, as described in [RFC 4960, Appendix
  B](http://tools.ietf.org/html/rfc4960#appendix-B). If provided, Cloud Storage will only create the file if the value matches the value calculated by the service. Do not provide if also providing a `checksum: :crc32c` or `checksum: :all` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **md5** (String) *(defaults to: nil)* --- The MD5 hash of the file data. If provided, Cloud Storage will only create the file if the value matches the value calculated by the service. Do not provide if also providing a `checksum: :md5` or `checksum: :all` argument. See [Validation](https://cloud.google.com/storage/docs/hashes-etags) for more information.
- **metadata** (Hash) *(defaults to: nil)* --- A hash of custom, user-provided web-safe keys and arbitrary string values that will returned with requests for the file as "x-goog-meta-" response headers.
- **storage_class** (Symbol, String) *(defaults to: nil)* --- Storage class of the file. Determines how the file is stored and determines the SLA and the cost of storage. Accepted values include `:standard`, `:nearline`, `:coldline`, and `:archive`, as well as the equivalent strings returned by [#storage_class](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_storage_class_instance_ "Google::Cloud::Storage::Bucket#storage_class (method)"). `:multi_regional`, `:regional`, and `durable_reduced_availability` are accepted legacy storage classes. For more information, see [Storage
  Classes](https://cloud.google.com/storage/docs/storage-classes) and [Per-Object Storage
  Class](https://cloud.google.com/storage/docs/per-object-storage-class). The default value is the default storage class for the bucket.
- **encryption_key** (String) *(defaults to: nil)* --- Optional. A customer-supplied, AES-256 encryption key that will be used to encrypt the file. Do not provide if `kms_key` is used.
- **kms_key** (String) *(defaults to: nil)* --- Optional. Resource name of the Cloud KMS key, of the form `projects/my-prj/locations/kr-loc/keyRings/my-kr/cryptoKeys/my-key`, that will be used to encrypt the file. The KMS key ring must use the same location as the bucket.The Service Account associated with your project requires access to this encryption key. Do not provide if `encryption_key` is used.
- **if_generation_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the file.
- **if_generation_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current generation does not match the given value. If no live file exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the file.
- **if_metageneration_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration matches the given value.
- **if_metageneration_not_match** (Integer) *(defaults to: nil)* --- Makes the operation conditional on whether the file's current metageneration does not match the given value.
**Returns**

- ([Google::Cloud::Storage::File](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-File.md.txt))
**Raises**

- (ArgumentError)
**Examples**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.create_file "path/to/local.file.ext"
```

Specifying a destination path:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext"
```

Providing a customer-supplied encryption key:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

# Key generation shown for example purposes only. Write your own.
cipher = OpenSSL::Cipher.new "aes-256-cfb"
cipher.encrypt
key = cipher.random_key

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext",
                   encryption_key: key

# Store your key and hash securely for later use.
file = bucket.file "destination/path/file.ext",
                   encryption_key: key
```

Providing a customer-managed Cloud KMS encryption key:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

# KMS key ring must use the same location as the bucket.
kms_key_name = "projects/a/locations/b/keyRings/c/cryptoKeys/d"

bucket.create_file "path/to/local.file.ext",
                   "destination/path/file.ext",
                   kms_key: kms_key_name

file = bucket.file "destination/path/file.ext"
file.kms_key #=> kms_key_name
```

Create a file with gzip-encoded data.

```ruby
require "zlib"
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

gz = StringIO.new ""
z = Zlib::GzipWriter.new gz
z.write "Hello world!"
z.close
data = StringIO.new gz.string

bucket = storage.bucket "my-bucket"

bucket.create_file data, "path/to/gzipped.txt",
                   content_encoding: "gzip"

file = bucket.file "path/to/gzipped.txt"

# The downloaded data is decompressed by default.
file.download "path/to/downloaded/hello.txt"

# The downloaded data remains compressed with skip_decompress.
file.download "path/to/downloaded/gzipped.txt",
              skip_decompress: true
```

### #user_project

```ruby
def user_project()
```
A boolean value or a project ID string to indicate the project to
be billed for operations on the bucket and its files. If this
attribute is set to `true`, transit costs for operations on the bucket
will be billed to the current project for this client. (See
[Project#project](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_project_instance_ "Google::Cloud::Storage::Project#project (method)") for the ID of the current project.) If this
attribute is set to a project ID, and that project is authorized for
the currently authenticated service account, transit costs will be
billed to that project. This attribute is required with requester
pays-enabled buckets. The default is `nil`.


In general, this attribute should be set when first retrieving the
bucket by providing the `user_project` option to [Project#bucket](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_bucket_instance_ "Google::Cloud::Storage::Project#bucket (method)").

<br />

See also [#requester_pays=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_requester_pays__instance_ "Google::Cloud::Storage::Bucket#requester_pays= (method)") and [#requester_pays](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_requester_pays_instance_ "Google::Cloud::Storage::Bucket#requester_pays (method)").
**Example**

Setting a non-default project:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "other-project-bucket", user_project: true
files = bucket.files # Billed to current project
bucket.user_project = "my-other-project"
files = bucket.files # Billed to "my-other-project"
```

### #user_project=

```ruby
def user_project=(value)
```
A boolean value or a project ID string to indicate the project to
be billed for operations on the bucket and its files. If this
attribute is set to `true`, transit costs for operations on the bucket
will be billed to the current project for this client. (See
[Project#project](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_project_instance_ "Google::Cloud::Storage::Project#project (method)") for the ID of the current project.) If this
attribute is set to a project ID, and that project is authorized for
the currently authenticated service account, transit costs will be
billed to that project. This attribute is required with requester
pays-enabled buckets. The default is `nil`.


In general, this attribute should be set when first retrieving the
bucket by providing the `user_project` option to [Project#bucket](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Project.md.txt#Google__Cloud__Storage__Project_bucket_instance_ "Google::Cloud::Storage::Project#bucket (method)").

<br />

See also [#requester_pays=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_requester_pays__instance_ "Google::Cloud::Storage::Bucket#requester_pays= (method)") and [#requester_pays](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_requester_pays_instance_ "Google::Cloud::Storage::Bucket#requester_pays (method)").
**Example**

Setting a non-default project:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "other-project-bucket", user_project: true
files = bucket.files # Billed to current project
bucket.user_project = "my-other-project"
files = bucket.files # Billed to "my-other-project"
```

### #versioning=

```ruby
def versioning=(new_versioning)
```
Updates whether [Object
Versioning](https://cloud.google.com/storage/docs/object-versioning)
is enabled for the bucket.


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **new_versioning** (Boolean) --- true if versioning is to be enabled for the bucket.

### #versioning?

```ruby
def versioning?() -> Boolean
```
Whether [Object
Versioning](https://cloud.google.com/storage/docs/object-versioning)
is enabled for the bucket.
**Returns**

- (Boolean)

### #website_404

```ruby
def website_404() -> String
```
The page returned from a static website served from the bucket when a
site visitor requests a resource that does not exist.
**Returns**

- (String)

### #website_404=

```ruby
def website_404=(website_404)
```
Updates the page returned from a static website served from the bucket
when a site visitor requests a resource that does not exist.


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").

### #website_main

```ruby
def website_main() -> String
```
The main page suffix for a static website. If the requested object
path is missing, the service will ensure the path has a trailing '/',
append this suffix, and attempt to retrieve the resulting object. This
allows the creation of index.html objects to represent directory
pages.
**Returns**

- (String) --- The main page suffix.

### #website_main=

```ruby
def website_main=(website_main)
```
Updates the main page suffix for a static website.


<br />

To pass metageneration preconditions, call this method within a
block passed to [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_update_instance_ "Google::Cloud::Storage::Bucket#update (method)").
**Parameter**

- **website_main** (String) --- The main page suffix.