benonymus
Sending picture to elixir api in multipart/form-data as json parsing in api
Hey I am trying to send a picture to my api, and the api want an id and a user so this is how I am trying to send it:
selectPicture() {
ImagePicker.openPicker({
cropping: true
}).then(image => {
console.log(image);
var bodyFormData = new FormData();
var user = JSON.stringify({
avatar: image[0]
});
bodyFormData.append("user", user);
bodyFormData.append("id", 1);
console.log(bodyFormData);
axios({
method: "put",
url: "http://xxxxxxx/api/user",
data: bodyFormData,
config: {
headers: { "content-type": "multipart/form-data" }
}
})
not sure if this is the best way, so I would be open for suggestions
so we receive it in the update function that is waiting for these 2:
def update(conn, %{"id" => id, "user" => user_params})
but it seems like for one in the log of the api that there is no plug upload just this as user_params:.
params: %{
"id" => "1",
"user" => "{\"avatar\":{\"size\":117832,\"mime\":\"image/jpeg\",\"height\":960,\"width\":960,\"path\":\"file://
/storage/emulated/0/DCIM/IMMQY/IMG_20180911042057_131.jpg\"}}"
}
how could theis be parsed or worked around or done nicely?
Popular in Questions
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
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
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
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
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
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New








