yeroc
Plug.Upload Arc Ecto - puzzled on what to do when creating a Mock testing file
Hi all!
I’m playing around with Arc Ecto reading the docs and following along with this tutorial .
I’m a bit puzzled on what to do when creating a Mock testing file to verify the local Ecto upload and how to correctly use %Plug.Upload{}. My code-
defmodule Posts.Mock do
def file_upload(path) do
%Plug.Upload{
path: Path.expand(path),
filename: Path.basename(path),
content_type: MIME.from_path(path)
}
end
end
So that in IEx I can try something like
avatar = Mock.file_upload("~/Pictures/some-image.png")
%User{}
|> User.changeset(%{name: "Shey", avatar: avatar})
|> Repo.insert()
My error-
Plug.Upload.__struct__/1 is undefined
Can someone help me understand what I’m supposed to do here? Not finding my answer in the docs, sure I’m missing something simple and fundamental. ![]()
Thanks for any help!
Most Liked
kokolegorille
Not the answer You might look… but it might be useful.
Arc is not really the go to for file uploads, it’s last update was in 2018.
There is a fork of Arc, it is called Waffle.
BTW I use Plug.Upload in my test too. I just don’t wrap it in a Mock module.
kokolegorille
You might need to have Plug too, if You don’t use Phoenix
kokolegorille
I started with Arc, and switching to Waffle was a drop in replacement.
If it is for mock, don’t forget to add Plug dependency as only: :test
Waffle Ecto is just some helpers to play nicely with Struct, not much more… it allows cast_attachment
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








