Media

The changeset for the initial version of a Media schema will be created by the create_initial_changeset/4 function exposed by the Storage.Media module.

Given that the database does not know what KSUIDs are, we generate a unique identifier at this stage. It will also be used to generate a storage_key, that is the actual name of the file stored on the cloud storage:

$ cat apps/elixir_drip/lib/elixir_drip/storage/media.exdefmodule ElixirDrip.Storage.Media do  use Ecto.Schema  alias __MODULE__  alias Ecto.Changeset  # ...  def create_initial_changeset(user_id, file_name, full_path,   file_size) do    id = Ksuid.generate()    attrs = %{      id: id,      user_id: user_id,      storage_key: generate_storage_key(id, file_name), encryption_key: Encryption.generate_key(), ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.