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

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement