Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

cast_filename doesn't work in local storage.  #48

Description

@loongmxbt

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions