Where Arc is triggered when upload a file?

Hi,

I’m using Arc and Arc Ecto to upload a file and I see nowhere explicit usage of store function yet it works. I read source code and I don’t see anything strange here - lot of __using__ which creates functions and in proper Arc.Storage (Local or S3) file is created.

I just don’t see how my code triggers Arc.

Your code does not triggers store directly I guess, but you had to call cast_attachments to make it work.

It maps through params, picks the uploaded files Plug.Upload, extracts the emporary paths, then, it calls cast:

https://github.com/stavro/arc_ecto/blob/465de3ea54c7d9b5f0bbf7402b50f7c8eae4e8b8/lib/arc_ecto/schema.ex#L53

Since your schema defines the fields as custom type, Ecto knows that a cast function from this module should be called. And since it is present and included from arc, it does get called, and call store:

https://github.com/stavro/arc_ecto/blob/465de3ea54c7d9b5f0bbf7402b50f7c8eae4e8b8/lib/arc_ecto/type.ex#L11

Thanks, I didn’t check the Arc.Ecto.
Great job! :slight_smile: