Skip to content

Instantly share code, notes, and snippets.

@rbnpercy
Created July 7, 2018 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbnpercy/f1856b39562bb87df817355b5d77de57 to your computer and use it in GitHub Desktop.
Save rbnpercy/f1856b39562bb87df817355b5d77de57 to your computer and use it in GitHub Desktop.
def create(conn, %{"photo" => %{"image" => image_params} = photo_params}) do
album_id = photo_params["album_id"]
ExAws.S3.put_bucket("#{album_id}", "")
|> ExAws.request()
Enum.map(image_params, fn(img) ->
album = album_id
ext = Path.extname(img.filename)
u = Ecto.UUID.generate
flnm = "#{u}#{ext}"
{:ok, file_binary} = File.read(img.path)
s3_bucket = album
{:ok, _} =
ExAws.S3.put_object(s3_bucket, flnm, file_binary)
|> ExAws.request()
store(conn, flnm, album)
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment