diff options
-rw-r--r-- | lib/the_transcriber_backend/endpoint.ex | 5 | ||||
-rw-r--r-- | web/controllers/audio_file_controller.ex | 9 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/the_transcriber_backend/endpoint.ex b/lib/the_transcriber_backend/endpoint.ex index a7b1478..32987a5 100644 --- a/lib/the_transcriber_backend/endpoint.ex +++ b/lib/the_transcriber_backend/endpoint.ex @@ -25,9 +25,10 @@ defmodule TheTranscriberBackend.Endpoint do plug Plug.Logger plug Plug.Parsers, - parsers: [:urlencoded, :multipart, :json], + parsers: [:urlencoded, :multipart, :json, :length], pass: ["*/*"], - json_decoder: Poison + json_decoder: Poison, + length: 80_000_000 plug Plug.MethodOverride plug Plug.Head 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 |