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?