My model paper looks like this.
schema "papers" do
field :title, :string
field :file, Exfile.Ecto.File
field :content_type, :string
field :filename, :string
belongs_to :topic, Confer.Topic
belongs_to :user, Confer.User
has_many :reviews, Confer.Review
timestamps()
end
and changeset looks like this
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:title, :file, :topic_id, :user_id, :content_type, :filename])
|> validate_required([:title, :topic_id, :file, :user_id])
|> validate_content_type(:file, ~w(application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document application/zip))
|> cast_content_type(:file, :content_type)
|> cast_filename(:file, :filename) # BUG: filename not inserted
|> Exfile.Ecto.prepare_uploads([:file])
end
When I upload a file, there is filename field at first. filename: "TensorFlow whitepaper2015.pdf".
But when goes to INSERT INTO, there is not a filename. Can't figure out why.
[info] POST /papers
[debug] Processing by Confer.PaperController.create/2
Parameters: %{"_csrf_token" => "X1oPfAV4ATE0DA9aCz4CB2Qffy53EAAA7md+v3FVAcYinpfA+y9T9A==", "_utf8" => "✓", "paper" => %{"file" => %Plug.Upload{content_type: "application/pdf", filename: "TensorFlow whitepaper2015.pdf", path: "/var/folders/wl/8_mrlnx52ls04sfl1my7g7l80000gn/T//plug-1472/multipart-956497-510178-2"}, "title" => "ppp", "topic_id" => "1"}}
Pipelines: [:protected]
[debug] QUERY OK db=0.3ms
SELECT t0."name", t0."id" FROM "topics" AS t0 ORDER BY t0."id" []
[debug] QUERY OK db=0.1ms
begin []
[debug] QUERY OK db=1.0ms
INSERT INTO "papers" ("content_type","file","title","topic_id","user_id","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7) RETURNING "id" ["application/pdf", "exfile://store/b9fea1752b7288c4aa71cb7bc0b58c9db6fb52f690d98d5c19d8c479e11f", "ppp", 1, 1, {{2016, 9, 4}, {2, 34, 57, 0}}, {{2016, 9, 4}, {2, 34, 57, 0}}]
[debug] QUERY OK db=0.3ms
Really wish your help! Thanks!
My model
paperlooks like this.and changeset looks like this
When I upload a file, there is
filenamefield at first.filename: "TensorFlow whitepaper2015.pdf".But when goes to
INSERT INTO, there is not afilename. Can't figure out why.Really wish your help! Thanks!