我有一个Ecto架构,它使用弧上传器作为字段类型。
schema "files" do
field :name, :string
field :locked, :boolean, default: false
field :mime_type, :string
field :path, Splish.Assets.FilesUploader.Type
field :size, :integer
belongs_to :user, Splish.Accounts.User
timestamps()
end
我想为此添加一个exmachina工厂
def file_factory do
%File{
name: "Gyldendal",
locked: false,
mime_type: "png",
size: 200,
# path: "test/support/image.png",
user: insert(:user)
}
end
我该怎么做?
答案 0 :(得分:2)
上传定义文件响应接受的Avatar.store/1 之一:
- 本地文件的路径
- 远程http或https文件的路径
- 带有文件名和路径键的地图(例如,%Plug.Upload {})
- 带有文件名和二进制密钥的地图(例如,%{filename:" image.png",二进制:<<<<< 255,255,255,...>>}}
- 由上述文件格式之一和范围对象组成的两元组。
我愿意:
@file_upload %Plug.Upload{
content_type: "image/png",
filename: "image.png",
path: "test/support/image.png" }
def file_factory do
%File{
name: "Gyldendal",
locked: false,
mime_type: "png",
size: 200,
path: @file_upload, # or with scope {@file_upload, %File{}}
user: insert(:user)
}
end