aboutsummaryrefslogtreecommitdiff
path: root/web/controllers
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2017-01-25 18:03:24 +0100
committerneodarz <neodarz@neodarz.net>2017-01-25 18:03:24 +0100
commitdde39c5c3853d70d2ea745e93f3624b5b0214fa2 (patch)
tree129c6dad78a0bbf3251ed179fd2b2b08c526827c /web/controllers
parent84ea469e79f71929aa55b6e9e60fe53042bb7808 (diff)
downloadthe_transcriber_backend-dde39c5c3853d70d2ea745e93f3624b5b0214fa2.tar.xz
the_transcriber_backend-dde39c5c3853d70d2ea745e93f3624b5b0214fa2.zip
Add good way for add and modify filethe-elixir-wayf_upload_file
Diffstat (limited to '')
-rw-r--r--web/controllers/audio_file_controller.ex26
1 files changed, 17 insertions, 9 deletions
diff --git a/web/controllers/audio_file_controller.ex b/web/controllers/audio_file_controller.ex
index dbcb6f9..db90da7 100644
--- a/web/controllers/audio_file_controller.ex
+++ b/web/controllers/audio_file_controller.ex
@@ -18,13 +18,12 @@ defmodule TheTranscriberBackend.AudioFileController do
path = "/media/phoenix_test/#{upload.filename}"
File.cp(upload.path, path)
- # "Non-elixir" way of doing things
- changeset = AudioFile.changeset(%AudioFile{},
+ changeset = AudioFile.changeset(%AudioFile{},
%{audio_path: path,
transcription_file_path: transcription_file_path,
audio_duration: audio_duration})
- IO.inspect changeset
+ IO.inspect changeset
case Repo.insert(changeset) do
{:ok, _audio_file} ->
@@ -38,10 +37,10 @@ defmodule TheTranscriberBackend.AudioFileController do
- def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "transcription_file_path" => transcription_file_path}}) do
-
- ## Do something here if no file has been uploaded
- end
+# def create(conn, %{"audio_file" => %{"audio_duration" => audio_duration, "transcription_file_path" => transcription_file_path}}) do
+#
+# ## Do something here if no file has been uploaded
+# end
def show(conn, %{"id" => id}) do
audio_file = Repo.get!(AudioFile, id)
@@ -54,9 +53,18 @@ defmodule TheTranscriberBackend.AudioFileController do
render(conn, "edit.html", audio_file: audio_file, changeset: changeset)
end
- def update(conn, %{"id" => id, "audio_file" => audio_file_params}) do
+ def update(conn, %{"id" => id, "audio_file" => %{"audio_duration" => audio_duration, "audio_path" => upload, "transcription_file_path" => transcription_file_path}}) do
+
+ path = "/media/phoenix_test/#{upload.filename}"
+ File.cp(upload.path, path)
+
audio_file = Repo.get!(AudioFile, id)
- changeset = AudioFile.changeset(audio_file, audio_file_params)
+ #changeset = AudioFile.changeset(audio_file, audio_file_params)
+
+ changeset = AudioFile.changeset(audio_file,
+ %{audio_path: path,
+ transcription_file_path: transcription_file_path,
+ audio_duration: audio_duration})
case Repo.update(changeset) do
{:ok, audio_file} ->