CloudflareStream.TusClient (cloudflare_stream v0.2.0)

A minimal client for the https://tus.io protocol. With fixes for working with cloudflare

Link to this section Summary

Functions

Uploads local file from path to base_url

Link to this section Types

Link to this type

upload_error()

Specs

upload_error() ::
  :file_error
  | :generic
  | :location
  | :not_supported
  | :too_large
  | :too_many_errors
  | :transport
  | :unfulfilled_extensions

Link to this section Functions

Link to this function

upload(base_url, path, opts \\ [])

Specs

upload(binary(), binary(),
  metadata: binary(),
  max_retries: integer(),
  chunk_len: integer(),
  headers: list(),
  ssl: list(),
  follow_redirect: boolean()
) :: {:ok, binary()} | {:error, upload_error()}

Uploads local file from path to base_url

Example:


  headers = [
    {"X-Auth-Email", "myemail@gmail.com"},
    {"X-Auth-Key", "myapikey"}
  ]

  metadata = %{
    "filetype" => "video/mp4", 
    "name" => "Cat is riding on a bike EVERYONE WATCH THIS", 
    "requiresignedurls" => "true",
    "my_custom_metadatafield" => "123"
  } 

  opts = [
    chunk_len: 5_242_880,
    headers: headers,
    metadata: metadata
  ]
  path = "priv/static/files/myvideo.mp4"

  CloudflareStream.TusClient.upload(
    "https://api.cloudflare.com/client/v4/accounts/_YOUR_ACCOUNT_ID_HERE_/stream",
    path,
    opts
  )