Giter Club home page Giter Club logo

Comments (7)

stavro avatar stavro commented on August 29, 2024

Can I see your controller?

from arc_ecto.

tompesman avatar tompesman commented on August 29, 2024

It's a https://github.com/falood/maru api endpoint:

defmodule Blog.UserApi do
  use Maru.Router

  params do
    optional :name, type: String
    optional :avatar, type: File
  end
  put "/user" do
    token = List.first(get_req_header(conn, "auth-token"))
    user = Blog.Repo.get_by(Blog.User, auth_token: token)

    IO.inspect params
    changeset = Blog.User.changeset_update(user, params)

    case Blog.Repo.update(changeset) do
      {:ok, user} ->
        conn
        |> put_status(:ok)
        |> json(Blog.CurrentUserEntity.serialize(user))
      {:error, _changeset} ->
        conn
        |> put_status(:unprocessable_entity)
        |> json(%{error: "Invalid request"})
    end
  end
end

The output of the IO.inspect params is:

%{avatar: %Plug.Upload{content_type: "image/png", filename: "1024.png",
   path: "/var/folders/85/gh23xrjx3pgdl8bd14lw6jx80000gn/T//plug-1450/multipart-790033-460458-8"},
  name: "Test"}

So the avatar field produces a Plug.Upload. That should be correct I think.

from arc_ecto.

tompesman avatar tompesman commented on August 29, 2024

Fixed it. Not sure if I'm sending something strange or the docs are missing a single char. 😬

  @required_fields ~w()
  @optional_fields ~w(name)

  @required_file_fields ~w()
  @optional_file_fields ~w(avatar)a  # <-- added 'a' here

Or this line returns always an empty array: https://github.com/stavro/arc_ecto/blob/master/lib/arc_ecto/model.ex#L24

from arc_ecto.

stavro avatar stavro commented on August 29, 2024

Interesting! Your param keys are coerced to atoms, whereas a normal phoenix app they are not:

This is a typical params object (note the string keys, not atoms):

%{"avatar" => %Plug.Upload{content_type: "image/gif", filename: "nav.gif",
   path: "/var/folders/25/l2rtbqcs6k3bqpj3fldgnplw0000gn/T//plug-1450/multipart-980282-311833-6"},
  "business_id" => "1"}

from arc_ecto.

stavro avatar stavro commented on August 29, 2024

It looks like Ecto under the hood converts them all to strings before processing.. We should do something similar here then.

https://github.com/elixir-lang/ecto/blob/master/lib/ecto/changeset.ex#L413-L426

from arc_ecto.

stavro avatar stavro commented on August 29, 2024

Closed via ceb5eb1.

from arc_ecto.

tompesman avatar tompesman commented on August 29, 2024

Awesome! 😄 👍

from arc_ecto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.