diff options
author | neodarz <neodarz@neodarz.net> | 2017-01-25 11:50:27 +0100 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2017-01-25 11:50:27 +0100 |
commit | 8e65ac05eb7778785602f4504465e1dcbf035812 (patch) | |
tree | 82f5178be54b732e289ba2ffadf02b4de6099aba /web | |
parent | 033d07a519bac03fdfd28ca15e09cc287e80fd14 (diff) | |
download | the_transcriber_backend-8e65ac05eb7778785602f4504465e1dcbf035812.tar.xz the_transcriber_backend-8e65ac05eb7778785602f4504465e1dcbf035812.zip |
Add unfonctional code for upload a file
Diffstat (limited to 'web')
-rw-r--r-- | web/controllers/audio_file_controller.ex | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/web/controllers/audio_file_controller.ex b/web/controllers/audio_file_controller.ex index 8cf5a00..3a73e87 100644 --- a/web/controllers/audio_file_controller.ex +++ b/web/controllers/audio_file_controller.ex @@ -14,12 +14,18 @@ defmodule TheTranscriberBackend.AudioFileController do end def create(conn, %{"audio_file" => audio_file_params}) do + if upload = audio_file_params["audio_path"] do + extension = Path.extname(upload.filename) + path = "/media/phoenix_test/#{upload.filename}" + File.cp(upload.path, path) + end changeset = AudioFile.changeset(%AudioFile{}, audio_file_params) + Ecto.Changeset.put_change(changeset, :audio_path, path) case Repo.insert(changeset) do {:ok, _audio_file} -> conn - |> put_flash(:info, "Audio file created successfully.") + |> put_flash(:info, "Audio file uploaded successfully.") |> redirect(to: audio_file_path(conn, :index)) {:error, changeset} -> render(conn, "new.html", changeset: changeset) @@ -56,6 +62,7 @@ defmodule TheTranscriberBackend.AudioFileController do # Here we use delete! (with a bang) because we expect # it to always work (and if it does not, it will raise). + File.rm(audio_file.audio_path) Repo.delete!(audio_file) conn |