Cloud Storage API - Module Google::Cloud::Storage (v1.57.1) Stay organized with collections Save and categorize content based on your preferences.
Reference documentation and code samples for the Cloud Storage API module Google::Cloud::Storage.
Google Cloud Storage
Google Cloud Storage is an Internet service to store data in Google'scloud. It allows world-wide storage and retrieval of any amount of dataand at any time, taking advantage of Google's own reliable and fastnetworking infrastructure to perform data operations in a cost effectivemanner.
SeeStorage Overview.
Methods
.anonymous
defself.anonymous(retries:nil,timeout:nil,open_timeout:nil,read_timeout:nil,send_timeout:nil,endpoint:nil,max_elapsed_time:nil,base_interval:nil,max_interval:nil,multiplier:nil,upload_chunk_size:nil,universe_domain:nil)->Google::Cloud::Storage::ProjectCreates an unauthenticated, anonymous client for retrieving public datafrom the Storage service. Each call creates a new connection.
- retries (Integer)(defaults to: nil) — Number of times to retry requests on servererror. The default value is
3. Optional. - max_elapsed_time (Integer)(defaults to: nil) — Total time in seconds that requests are allowed to keep being retried.
- base_interval (Float)(defaults to: nil) — The initial interval in seconds between tries.
- max_interval (Integer)(defaults to: nil) — The maximum interval in seconds that any individual retry can reach.
- multiplier (Integer)(defaults to: nil) — Each successive interval grows by this factor. A multipler of 1.5 means the nextinterval will be 1.5x the current interval.
- timeout (Integer)(defaults to: nil) — (default timeout) The max duration, in seconds, to wait before timing out. Optional.If left blank, the wait will be at most the time permitted by the underlying HTTP/RPC protocol.
- open_timeout (Integer)(defaults to: nil) — How long, in seconds, before failed connections time out. Optional.
- read_timeout (Integer)(defaults to: nil) — How long, in seconds, before requests time out. Optional.
- send_timeout (Integer)(defaults to: nil) — How long, in seconds, before receiving response from server times out. Optional.
- endpoint (String)(defaults to: nil) — Override of the endpoint host name. Optional.If the param is nil, uses the default endpoint.
- universe_domain (String)(defaults to: nil) — Override of the universe domain. Optional.If unset or nil, uses the default unvierse domain
- upload_chunk_size (Integer)(defaults to: nil) — The chunk size of storage upload, in bytes.The default value is 100 MB, i.e. 104_857_600 bytes. To disable chunking and uploadthe complete file regardless of size, pass 0 as the chunk size.
Useskip_lookup to avoid retrieving non-public metadata:
require"google/cloud/storage"storage=Google::Cloud::Storage.anonymousbucket=storage.bucket"public-bucket",skip_lookup:truefile=bucket.file"path/to/public-file.ext",skip_lookup:truedownloaded=file.downloaddownloaded.rewinddownloaded.read#=> "Hello world!"
.configure
defself.configure()->Google::Cloud::ConfigConfigure the Google Cloud Storage library.
The following Storage configuration parameters are supported:
project_id- (String) Identifier for a Storage project. (Theparameterprojectis considered deprecated, but may also be used.)credentials- (String, Hash, Google::Auth::Credentials) The path tothe keyfile as a String, the contents of the keyfile as a Hash, or aGoogle::Auth::Credentials object. (SeeCredentials) (Theparameterkeyfileis considered deprecated, but may also be used.)endpoint- (String) Override of the endpoint host name, ornilto use the default endpoint.scope- (String, Arrayretries- (Integer) Number of times to retry requests on servererror.max_elapsed_time- (Integer) Total time in seconds that requestsare allowed to keep being retried.base_interval- (Float) The initial interval in seconds between tries.max_interval- (Integer) The maximum interval in seconds that anyindividual retry can reach.multiplier- (Integer) Each successive interval grows by this factor.A multipler of 1.5 means the next interval will be 1.5x the current interval.timeout- (Integer) (default timeout) The max duration, in seconds, to wait before timing out. If left blank, the wait will be at most the time permitted by the underlying HTTP/RPC protocol.open_timeout- (Integer) How long, in seconds, before failed connections time out.read_timeout- (Integer) How long, in seconds, before requests time out.send_timeout- (Integer) How long, in seconds, before receiving response from server times out.upload_chunk_size- (Integer) The chunk size of storage upload, in bytes.
- (Google::Cloud.configure.storage)
- (Google::Cloud::Config) — The configuration object theGoogle::Cloud::Storage library uses.
.new
defself.new(project_id:nil,credentials:nil,scope:nil,retries:nil,timeout:nil,open_timeout:nil,read_timeout:nil,send_timeout:nil,endpoint:nil,project:nil,keyfile:nil,max_elapsed_time:nil,base_interval:nil,max_interval:nil,multiplier:nil,upload_chunk_size:nil,universe_domain:nil)->Google::Cloud::Storage::ProjectCreates a new object for connecting to the Storage service.Each call creates a new connection.
For more information on connecting to Google Cloud see theAuthentication Guide.
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
- project_id (String)(defaults to: nil) — Project identifier for the Storage serviceyou are connecting to. If not present, the default project for thecredentials is used.
- credentials (Google::Auth::Credentials)(defaults to: nil) — A Google::Auth::Credentialsobject. (SeeCredentials)
- scope (String, Array<String>)(defaults to: nil) —
The OAuth 2.0 scopes controllingthe set of resources and operations that the connection can access.SeeUsing OAuth 2.0 to Access GoogleAPIs.
The default scope is:
https://www.googleapis.com/auth/devstorage.full_control
- retries (Integer)(defaults to: nil) — Number of times to retry requests on servererror. The default value is
3. Optional. - max_elapsed_time (Integer)(defaults to: nil) — Total time in seconds that requests are allowed to keep being retried.
- base_interval (Float)(defaults to: nil) — The initial interval in seconds between tries.
- max_interval (Integer)(defaults to: nil) — The maximum interval in seconds that any individual retry can reach.
- multiplier (Integer)(defaults to: nil) — Each successive interval grows by this factor. A multipler of 1.5 means the nextinterval will be 1.5x the current interval.
- timeout (Integer)(defaults to: nil) — (default timeout) The max duration, in seconds, to wait before timing out. Optional.If left blank, the wait will be at most the time permitted by the underlying HTTP/RPC protocol.
- open_timeout (Integer)(defaults to: nil) — How long, in seconds, before failed connections time out. Optional.
- read_timeout (Integer)(defaults to: nil) — How long, in seconds, before requests time out. Optional.
- send_timeout (Integer)(defaults to: nil) — How long, in seconds, before receiving response from server times out. Optional.
- endpoint (String)(defaults to: nil) — Override of the endpoint host name. Optional.If the param is nil, uses the default endpoint.
- universe_domain (String)(defaults to: nil) — Override of the universe domain. Optional.If unset or nil, uses the default unvierse domain
- upload_chunk_size (Integer)(defaults to: nil) — The chunk size of storage upload, in bytes.The default value is 100 MB, i.e. 104_857_600 bytes. To disable chunking and uploadthe complete file regardless of size, pass 0 as the chunk size.
- project (String)(defaults to: nil) — Alias for the
project_idargument. Deprecated. - keyfile (String)(defaults to: nil) — Alias for the
credentialsargument.Deprecated.
- (ArgumentError)
require"google/cloud/storage"storage=Google::Cloud::Storage.new(project_id:"my-project",credentials:"/path/to/keyfile.json")bucket=storage.bucket"my-bucket"file=bucket.file"path/to/my-file.ext"
Constants
GOOGLEAPIS_URL
value:"https://storage.googleapis.com".freeze
VERSION
value:"1.57.1".freeze
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-04 UTC.