How to sending multipart/form-data to client

I am trying to create an API. Part of the API should be able to store and retrieve images of the user. When the user wants to store an image, multipart/form-data is send (part image part JSON) which is now being handled by the create function.
def create(conn, %{"imageFile" => imageFileStruct, "jsonFile" => jsonFileStruct}) do
This function saves the image using arc to the local file system and saving the URL of the saved image to the DB.

The problem is, I have no idea how to go about sending the image (and a JSON file) back to the user. My current show function is the default one:

   def show(conn, %{"id" => id}) do
     image = Repo.get!(Image, id)
     render(conn, "show.json", image: image)
   end

In the struct image the image location of the previously saved image is present. How do I (efficiently) give the image and a JSON to the user? In an earlier post on this forum (earlier post) HTTPoison and multipart/form-data was used for this purpose. What would be the best method to use HTTPoison in Phoenix?

https://hexdocs.pm/plug/Plug.Conn.html#send_file/5

1 Like