yeroc

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. :upside_down_face:

Thanks for any help!

Most Liked

kokolegorille

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

kokolegorille

You might need to have Plug too, if You don’t use Phoenix

kokolegorille

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

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement