gcs v0.1.0 GCS View Source

A simple library to interact with Google Cloud Storage

Link to this section Summary

Link to this section Types

Link to this type

headers()

View Source
headers() :: [{String.t(), String.t()}]

Link to this section Functions

Link to this function

delete_object(bucket, gcs_file_path, headers \\ [], http_opts \\ [])

View Source
delete_object(any(), binary(), headers(), any()) ::
  {:ok, :deleted} | {:error, any()}

Deletes a file from GCS

Requires the bucket name and the gcs file location with filename.

Examples

iex> File.write!("file.txt", "hello")
:ok
iex> GCS.upload_object("my-bucket", "myfile.txt", "file.txt", "Application/txt")
{:ok, %{...}} # GCS Response
iex> GCS.make_public("my-bucket", "myfile.txt")
{:ok, %{...}} # GCS Response
iex> SomeHTTPClient.get("https://storage.googleapis.com/my-bucket/myfile.txt")
{:ok, %{body: "hello"}}
Link to this function

download_object(bucket, gcs_file_path, headers \\ [], http_opts \\ [])

View Source
download_object(any(), binary(), headers(), any()) :: {:ok, any()}

Downloads a file from GCS

Requires the bucket name and the gcs file location with filename.

Example: if the bucket is "my-bucket" and the gcs file path is "myfile.png", the file would be retrieved from "my-bucket" at the location "myfile.png".

More Examples

iex> File.write!("file.txt", "hello")
:ok
iex> GCS.upload_object("my-bucket", "myfile.txt", "file.txt", "Application/txt")
{:ok, %{...}} # GCS Response
iex> GCS.download_object("my-bucket", "myfile.txt")
"hello"
Link to this function

make_public(bucket, gcs_file_path, headers \\ [], http_opts \\ [])

View Source
make_public(any(), binary(), headers(), any()) :: {:ok, any()}

Makes a file in GCS publicly accessible

Requires the bucket name and the gcs file location with filename.

The file will be available at https://storage.googleapis.com/bucket/file_path

Example: if the bucket is "my-bucket" and the gcs file path is "myfile.png", the url would be https://storage.googleapis.com/my-bucket/myfile.png.

More Examples

iex> File.write!("file.txt", "hello")
:ok
iex> GCS.upload_object("my-bucket", "myfile.txt", "file.txt", "Application/txt")
{:ok, %{...}} # GCS Response
iex> GCS.make_public("my-bucket", "myfile.txt")
{:ok, %{...}} # GCS Response
iex> SomeHTTPClient.get("https://storage.googleapis.com/my-bucket/myfile.txt")
{:ok, %{body: "hello"}}
Link to this function

upload_object(bucket, gcs_file_path, file_path, content_type, headers \\ [], http_opts \\ [])

View Source
upload_object(any(), binary(), any(), any(), headers(), any()) ::
  {:ok, any()}

Uploads a file to GCS

Requires the bucket name, the desired gcs file location with desired filename, the path to the file to be uploaded, and the content type of the file.

Examples

iex> File.write!("file.txt", "hello")
:ok
iex> GCS.upload_object("my-bucket", "myfile.txt", "file.txt", "Application/txt")
{:ok, %{...}} # GCS Response