You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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!
The text was updated successfully, but these errors were encountered:
The problem ist that cast_content_type is not idempotent in that it not only adds content_type to changeset but also replaces the Plug.Upload file representation with Exfile.File representation with the latter not possessing the filename information.
Quick fix is to add cast_filename before cast_content_type to your changeset function. The aforementioned pull request makes cast_content_type idempotent.
* upstream/master:
Fix POSIX error typo
Better error message for failed uploads
Rename perform_uploads/2 back to perform_uploads!/2
Gracefully handle optional exfile fields not being set
Do not add processed file back to changeset in cast_content_type. Fixeskeichan34#43 and keichan34#48
Replace deprecated String.strip/1 with String.trim/1
My model
paper
looks like this.and changeset looks like this
When I upload a file, there is
filename
field 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!
The text was updated successfully, but these errors were encountered: