Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

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(), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content