Buckets.SignedURL (buckets v1.0.0-rc.2)

Represents a signed URL for direct access to objects in cloud storage.

Signed URLs provide temporary, secure access to objects without requiring authentication. They are commonly used for:

  • Direct file downloads from cloud storage
  • Direct uploads to cloud storage (especially with LiveView)
  • Temporary sharing of private files

Structure

A SignedURL contains:

  • :url - The complete signed URL string that can be used for access
  • :location - The Buckets.Location struct indicating where the object is stored

Usage

SignedURLs are typically generated by adapters through the url/2 callback:

{:ok, signed_url} = MyApp.Cloud.url(object, expires_in: 3600)

# Access the URL string
url_string = signed_url.url
# or use String.Chars protocol
url_string = to_string(signed_url)

LiveView Uploads

SignedURLs are used for direct uploads in LiveView:

{:ok, config} = MyApp.Cloud.live_upload(entry)
# config.url is a SignedURL for uploading

JSON Encoding

SignedURLs implement the Jason.Encoder protocol and encode to just the URL string:

Jason.encode!(%{upload_url: signed_url})
# {"upload_url": "https://storage.example.com/bucket/file?signature=..."}

Security Considerations

  • Signed URLs typically expire after a set time period
  • They should be treated as sensitive data
  • Different adapters have different expiration limits and security features

Summary

Functions

Converts a SignedURL to its URL string representation.

Types

@type t() :: %Buckets.SignedURL{location: Buckets.Location.t(), url: String.t()}

Functions

Link to this function

to_string(signed_url)

Converts a SignedURL to its URL string representation.

This function extracts just the URL string from the SignedURL struct. It's also used by the String.Chars protocol implementation.

Examples

iex> signed_url = %Buckets.SignedURL{url: "https://example.com/file?sig=123"}
iex> Buckets.SignedURL.to_string(signed_url)
"https://example.com/file?sig=123"

# Also works with Kernel.to_string/1
iex> to_string(signed_url)
"https://example.com/file?sig=123"