How to send a picture in json as from web to elixir

Hey from my web version when I upload an image this is the struct that is created:

 "user" => %{
      "avatar" => %Plug.Upload{
        content_type: "image/jpeg",
        filename: "ConceptArt_SneakySneaky_011 (2).jpg",
        path: "/tmp/plug-1536/multipart-1536590148-521595600991125-4"

how could i send a picture in similar fashion from a react native app?
with form-field? or is is doable in json? in postman it works with json, but i cannot send the picture there

It’s usually done with multipart.

1 Like

You can base64 encode the file/image in js then send it to the server.

Can’t answer specifically for reactive native, but from an Angular app I’ve had good success using FormData. For example, here’s my code for uploading a snapshot from a webcam:

public uploadSnapshot(snap: Blob) {
  let data = new FormData();
  data.append("data", snap, "snapshot");
  data.append("timestamp", (new Date()).toISOString());
  data.append("type", "image");"/api/camera", data)
    .subscribe(result => { }, errorResult => {
      console.error("(CameraService) Error saving snapshot: ", errorResult);