GcpGcs.Object (GcpGcs v0.2.0)

Copy Markdown View Source

Object metadata operations for the Google Cloud Storage JSON API.

Responses are the decoded JSON Object resource as a map with string keys. For transferring object bytes, see GcpGcs.Upload and GcpGcs.Download.

These functions are exposed through the top-level GcpGcs module.

Summary

Functions

Concatenates up to 32 source objects in the same bucket into dest_object.

Copies an object. Suitable for same-location copies; for large or cross-location copies prefer rewrite/5.

Deletes an object. Returns :ok on success.

Gets an object's metadata (not its contents).

Lists objects in a bucket.

Moves (renames) an object within a bucket. Requires a bucket with hierarchical namespace enabled.

Rewrites (copies) an object, following GCS rewrite tokens until the operation completes. Handles large and cross-location/cross-storage-class copies that a single copy/5 cannot.

Patches an object's metadata with attrs (a map of Object resource fields, e.g. %{"contentType" => "text/plain", "metadata" => %{"key" => "value"}}).

Functions

compose(bucket, dest_object, sources, opts \\ [])

@spec compose(String.t(), String.t(), [String.t() | map()], keyword()) ::
  {:ok, map()} | {:error, GcpGcs.Error.t()}

Concatenates up to 32 source objects in the same bucket into dest_object.

sources is a list of object names (strings) or maps with a "name" key.

Options

  • :attrs — destination Object resource fields (e.g. %{"contentType" => ...})
  • :timeout — request timeout in ms

copy(src_bucket, src_object, dst_bucket, dst_object, opts \\ [])

@spec copy(String.t(), String.t(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, GcpGcs.Error.t()}

Copies an object. Suitable for same-location copies; for large or cross-location copies prefer rewrite/5.

Options

  • :attrs — destination Object resource fields to set
  • :timeout — request timeout in ms

delete(bucket, object, opts \\ [])

@spec delete(String.t(), String.t(), keyword()) :: :ok | {:error, GcpGcs.Error.t()}

Deletes an object. Returns :ok on success.

get(bucket, object, opts \\ [])

@spec get(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, GcpGcs.Error.t()}

Gets an object's metadata (not its contents).

Options

  • :generation — a specific object generation
  • :timeout — request timeout in ms

list(bucket, opts \\ [])

@spec list(
  String.t(),
  keyword()
) ::
  {:ok, %{items: list(), prefixes: list(), next_page_token: String.t() | nil}}
  | {:error, GcpGcs.Error.t()}

Lists objects in a bucket.

Options

  • :prefix — filter to names starting with this prefix
  • :delimiter — collapse names with this delimiter into :prefixes (use "/" to list a single "directory" level)
  • :page_size — maximum results per page (maps to maxResults)
  • :page_token — pagination token
  • :start_offset / :end_offset — lexicographic range filters
  • :versionstrue to include non-current object versions

Returns {:ok, %{items: [...], prefixes: [...], next_page_token: token}}.

move(bucket, src_object, dst_object, opts \\ [])

@spec move(String.t(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, GcpGcs.Error.t()}

Moves (renames) an object within a bucket. Requires a bucket with hierarchical namespace enabled.

rewrite(src_bucket, src_object, dst_bucket, dst_object, opts \\ [])

@spec rewrite(String.t(), String.t(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, GcpGcs.Error.t()}

Rewrites (copies) an object, following GCS rewrite tokens until the operation completes. Handles large and cross-location/cross-storage-class copies that a single copy/5 cannot.

Options

  • :attrs — destination Object resource fields to set
  • :max_bytes_per_callmaxBytesRewrittenPerCall (must be a multiple of 1 MiB)
  • :timeout — request timeout per underlying call, in ms

Returns {:ok, object_resource} for the finished object.

update(bucket, object, attrs, opts \\ [])

@spec update(String.t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, GcpGcs.Error.t()}

Patches an object's metadata with attrs (a map of Object resource fields, e.g. %{"contentType" => "text/plain", "metadata" => %{"key" => "value"}}).