Elixir: how to send an image in api

I am using erlang httpc in elixir as :httpc.request(:post, {url, headers, content_type, body},[],[])in phoenix application to try to send image in api while i create body like

{:ok, data} = File.read(image.path) body = "{ \"param\": \"value\", \"file\": #{data}}" I am not sure where I am wrong, but the request works with the file parameter

My question is how to do this elixir?

+4
source share
1 answer

As stated above, I used erlcloud to boot into AWS, make sure that you export your AWS keys as you get started. In phoenix mix.exs deps add

{: erlcloud, github: "gleber / erlcloud"}

code example

def create(conn, params) do image = params["image"] image_url = to_char_list(image.filename}) {:ok, data} = File.read(image.path) :ssl.start() :erlcloud.start() :erlcloud_s3.put_object(__FOLDER__, image_url, file,[],[]) end

0
source

All Articles