benonymus
Questions about ARC in phoenix/elixir api
Hey I am trying to save a profile picture from my react native app with phoenix api.
So I started to use arc, following this guide: https://medium.com/@rafamossakowski/arc-carrierwave-for-phoenix-1064b2463fdf since I couldn’t find one that is using react native. It is working nicely with the website part, but my questions would be that:
How to send the picture form my app to the api in json?
And how to return the picture to the app from the api in json?
Thanks
Most Liked
stuartish
I’m sure this is too little too late, but in case anyone else has the same question, I think the best thing to do, if you need to save that file to S3 or a database, is to turn it into an upload plug. (Stole this from somewhere I can’t remember)
def get_plug(data) do
{:ok, binary} = Base.decode64(data)
with {:ok, path} <- Plug.Upload.random_file("upload"),
{:ok, file} <- File.open(path, [:write, :binary]),
:ok <- IO.binwrite(file, binary),
:ok <- File.close(file) do
{:ok, %Plug.Upload{path: path}}
end
end
That returns the struct you would have gotten had you uploaded a file directly via form-data (though it will be missing mimetype and filename).







