mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
Faster uploads, fix replacement of existing files
This commit is contained in:
parent
244ea56d0f
commit
dd85badae4
3 changed files with 19 additions and 1 deletions
|
@ -36,6 +36,22 @@ defmodule Philomena.Objects do
|
|||
end)
|
||||
end
|
||||
|
||||
#
|
||||
# Upload a file using multiple API calls, writing the
|
||||
# contents from the given path to storage.
|
||||
#
|
||||
@spec upload(String.t(), String.t()) :: any()
|
||||
def upload(key, file_path) do
|
||||
{_, mime} = Mime.file(file_path)
|
||||
|
||||
run_all(fn opts ->
|
||||
file_path
|
||||
|> ExAws.S3.Upload.stream_file()
|
||||
|> ExAws.S3.upload(opts[:bucket], key, content_type: mime)
|
||||
|> ExAws.request!(opts[:config_overrides])
|
||||
end)
|
||||
end
|
||||
|
||||
#
|
||||
# Copies a key from the source to the destination,
|
||||
# overwriting the destination object if its exists.
|
||||
|
|
|
@ -72,7 +72,7 @@ defmodule Philomena.Uploader do
|
|||
content type and permissions.
|
||||
"""
|
||||
def persist_file(path, file) do
|
||||
Objects.put(path, file)
|
||||
Objects.upload(path, file)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -10,6 +10,8 @@ defmodule PhilomenaWeb.Image.FileController do
|
|||
plug PhilomenaWeb.ScraperPlug, params_name: "image", params_key: "image"
|
||||
|
||||
def update(conn, %{"image" => image_params}) do
|
||||
Images.remove_hash(conn.assigns.image)
|
||||
|
||||
case Images.update_file(conn.assigns.image, image_params) do
|
||||
{:ok, image} ->
|
||||
conn
|
||||
|
|
Loading…
Reference in a new issue