Skip to content

Instantly share code, notes, and snippets.

@jeisenberg
Last active September 8, 2016 03:56
Show Gist options
  • Save jeisenberg/a0a5a7b8832cf56f3556e98256c51b55 to your computer and use it in GitHub Desktop.
Save jeisenberg/a0a5a7b8832cf56f3556e98256c51b55 to your computer and use it in GitHub Desktop.
def update(conn, %{"id" => id, "uploaded_image" => uploaded_image}) do
contents = uploaded_image.path
|> File.read!()
response = S3.put_object(System.get_env("AWS_BUCKET"), uploaded_image.filename, contents)
|> ExAws.request!()
case response do
%{status_code: 200} ->
# do something here after s3 uploads successfully
_ ->
# catch everything else as a wildcard and have them try again
conn
|> put_flash(:error, "Error uploading file")
|> redirect(to: "/admin/resource/"<>id<>"/edit?type=image")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment