-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #509 from eyra/fix-upload-local-fs
Fixed issues with local fs uploads
- Loading branch information
Showing
29 changed files
with
159 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
defmodule CoreWeb.UploadedFileController do | ||
use CoreWeb, :controller | ||
import CoreWeb.FileUploader, only: [get_static_path: 1] | ||
import CoreWeb.FileUploader, only: [get_upload_path: 1] | ||
|
||
def get(conn, %{"filename" => name}) do | ||
path = get_static_path(name) | ||
path = get_upload_path(name) | ||
send_file(conn, 200, path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,28 @@ | ||
defmodule Systems.Content.LocalFS do | ||
alias CoreWeb.Endpoint | ||
use CoreWeb, :verified_routes | ||
|
||
def store(tmp_path) do | ||
uuid = Ecto.UUID.generate() | ||
extname = Path.extname(tmp_path) | ||
id = "#{uuid}#{extname}" | ||
path = get_path(id) | ||
File.cp!(tmp_path, path) | ||
id | ||
def public_path, do: "/uploads" | ||
|
||
def get_public_url(path) do | ||
filename = Path.basename(path) | ||
~p"/uploads/#{filename}" | ||
end | ||
|
||
def storage_path(id) do | ||
get_path(id) | ||
def store(path, original_filename) do | ||
uuid = Ecto.UUID.generate() | ||
root_path = get_root_path() | ||
new_path = "#{root_path}/#{uuid}_#{original_filename}" | ||
File.cp!(path, new_path) | ||
new_path | ||
end | ||
|
||
def get_public_url(id) do | ||
"#{Endpoint.url()}/#{public_path()}/#{id}" | ||
def get_root_path do | ||
Application.get_env(:core, :upload_path) | ||
end | ||
|
||
def remove(id) do | ||
with {:ok, _} <- File.rm_rf(get_path(id)) do | ||
def remove(path) do | ||
with {:ok, _} <- File.rm_rf(path) do | ||
:ok | ||
end | ||
end | ||
|
||
defp get_path(id) do | ||
Path.join(get_root_path(), id) | ||
end | ||
|
||
def get_root_path do | ||
:core | ||
|> Application.get_env(:content, []) | ||
|> Access.fetch!(:local_fs_root_path) | ||
end | ||
|
||
def public_path, do: "/content" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.