benonymus

benonymus

Sending and recieveing a file(audio) from app to elixir api issue

Hey I am trying to send an audio recording from my react-native android app the request looks like this:

let data = new FormData();
        data.append("recording", {
          uri: rec._fsPath,
          type: "audio/mp4",
          name: "testRec",
          challenge_id: 1,
          user_id: 1,
          mod_score: 3
        });
        console.log(data);
        axios
          .post(
            config.API_URL + "recordings",
            { data },
            { headers: { Authorization: "Bearer " + this.props.auth.token } }
          )
          .then(res => res.data);

the params when arrive they look like this:

This typically happens when there is aparameter mismatch but may also happen when any of the other action arguments do not match. The request parameters are:
%{"data" => %{"_parts" => [["recording", %{"challenge_id" => 1, "mod_score" => 3, "name" => "testR ec", "type" => "audio/mp4", "uri" => "/data/user/0/com.cobrn/files/filename.mp4", "user_id" => 1}]]} }

and my api is expecting recording_params that goes here:

with {:ok, %Recording{} = recording} <- Web.create_recording(recording_params)

that goes here:

def create_recording(attrs \\ %{}) do

    %Recording{}
    |> Recording.changeset(attrs)
    |> Repo.insert()
  end

that goes to my schema that looks like this:

defmodule Userteam1.Web.Recording do
  use Ecto.Schema
  use Arc.Ecto.Schema
  import Ecto.Changeset

  schema "recordings" do
field(:path_to_recording, Userteam1Web.Recording.Type)
field(:mod_score, :integer)
belongs_to(:user, Userteam1.Web.User)
belongs_to(:challenge, Userteam1.Web.Challenge)
has_many(:comment, Userteam1.Web.Comment)

timestamps()
  end

  @doc false
  def changeset(recording, attrs) do
recording
|> cast(attrs, [:challenge_id, :user_id, :mod_score])
|> cast_attachments(attrs, [:path_to_recording])
|> validate_required([:path_to_recording])
  end
end

as you can see it should cast the attachment, as the documentation and examples showed for ARC and ARC-ecto but either the request is wrong in some form, or is it not attached, does append do what attach wants to take?
I know that this might be a lot to read, but I would really appreciate some help with this issue, and I think this could be good resource for other devs too in the future.

First Post!

benonymus

benonymus

ok I see the traction is big, I found that I might need to do something along these lines: https://github.com/stavro/arc/issues/220
that I thake the params and remap them, but the question then is how will it be a plug.upload struct?

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
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
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
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

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
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

We're in Beta

About us Mission Statement