fix images
This commit is contained in:
parent
d7559647e2
commit
3b63d75219
7 changed files with 85 additions and 76 deletions
|
|
@ -1,6 +1,8 @@
|
|||
defmodule ZoeyscomputerWeb.ImageController do
|
||||
use ZoeyscomputerWeb, :controller
|
||||
|
||||
import Mogrify
|
||||
|
||||
alias Zoeyscomputer.IdGenerator
|
||||
alias Zoeyscomputer.Images
|
||||
alias Zoeyscomputer.Images.Image
|
||||
|
|
@ -59,12 +61,23 @@ defmodule ZoeyscomputerWeb.ImageController do
|
|||
defp handle_upload(upload) do
|
||||
extension = Path.extname(upload.filename)
|
||||
id = IdGenerator.generate()
|
||||
key = "uploads/#{id}#{extension}"
|
||||
key = "uploads/#{id}.png"
|
||||
bucket = "imgs"
|
||||
|
||||
local_path = "/tmp/#{id}#{extension}"
|
||||
|
||||
IO.puts("upload path: #{upload.path}")
|
||||
{:ok, file_binary} = File.read(upload.path)
|
||||
|
||||
case ExAws.S3.put_object(bucket, key, file_binary)
|
||||
File.write!(local_path, file_binary)
|
||||
|
||||
IO.puts("wrote to #{local_path}")
|
||||
image = open(local_path) |> format("png") |> save()
|
||||
IO.inspect(image)
|
||||
|
||||
{:ok, new_file_binary} = File.read(image.path)
|
||||
|
||||
case ExAws.S3.put_object(bucket, key, new_file_binary, %{content_type: "image/png"})
|
||||
|> ExAws.request() do
|
||||
{:ok, _response} -> {:ok, id}
|
||||
{:error, reason} -> {:error, reason}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue