字段的无效或未知类型App.ImageFile.Type:filename Phoneix App

时间:2017-11-18 13:43:46

标签: google-cloud-storage phoenix-framework ecto

我尝试使用Arc来上传图片到Google云端存储,(在此之后 - https://maartenvanvliet.nl/2017/08/05/arc_uploads_to_google_cloud_storage/)但是,我在运行mix ecto.migrate时遇到了编译错误:

== Compilation error on file lib/codsonline/assets/image.ex ==
** (ArgumentError) invalid or unknown type App.ImageFile.Type for field :filename
    lib/ecto/schema.ex:1886: Ecto.Schema.check_type!/3
    lib/ecto/schema.ex:1507: Ecto.Schema.__field__/4
    lib/codsonline/assets/image.ex:8: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in 
Kernel.ParallelCompiler.spawn_compilers/1

我已经改变了我的架构:

  schema "images" do
    field :filename, :string
    field :name, :string

    timestamps()
  end

为:

  schema "images" do
    field :filename, App.ImageFile.Type
    field :name, :string

    timestamps()
  end

我的上传者/ image_file.ex:

defmodule Codsonline.ImageFile do
  use Arc.Definition

  # Include ecto support (requires package arc_ecto installed):
  use Arc.Ecto.Definition

  @versions [:original]

  def __storage, do: Arc.Storage.GCS

  def gcs_object_headers(:original, {file, _scope}) do
    [content_type: MIME.from_path(file.file_name)]
  end

end

我的语法有错吗?

更新

@dogbert指出我不是使用Codsonline而不是App,下面现在有效:

  schema "images" do
    field :filename, Codsonline.ImageFile.Type
    field :name, :string

    timestamps()
  end

0 个答案:

没有答案