In my app, the user can "import" a photo, where the server downloads the image to the local filesystem, puts the result into Plug.Upload, and does some stuff with Arc.Ecto before storing the path to the db. This is all working great in Debian, but is failing during Ecto.Changeset.cast on my Windows 10 machine.
File.mkdir("/tmp/import/")
filename = UUID.uuid4() <> "." <> extension
path = "/tmp/import/" <> filename
File.write!(path, imgbinary)
results
|> Map.put("photourl",%Plug.Upload{filename: filename, path: Path.absname(path)})
|> do_stuff_and_then_get_passed_to_changeset
Here's part of my params that I am giving to Changeset.cast (in Windows)
"photourl" => %Plug.Upload{content_type: nil,
filename: "17c032be-0237-4981-a9e5-1cfe693aed51.jpg",
path: "c:/tmp/import/17c032be-0237-4981-a9e5-1cfe693aed51.jpg"},
unix-equivalent (no problems):
"photourl" => %Plug.Upload{content_type: nil,
filename: "17c032be-0237-4981-a9e5-1cfe693aed51.jpg",
path: "/tmp/import/17c032be-0237-4981-a9e5-1cfe693aed51.jpg"},
part of my schema:
field :photourl, ImageUploader.Type
#(photourl is stored as text in postgres db)
The error part of the changeset:
errors: [photourl: {"is invalid", [type: ImageUploader.Type, validation: :cast]}]
defmodule ImageUploader do
use Arc.Definition
use Arc.Ecto.Definition
def __storage, do: Arc.Storage.Local
#other stuff that isn't relevant. I think Type comes from Arc or Arc.Ecto?
I'm not quite sure how to debug this even further. I am wondering if it has something to do with my path (but it's valid for both environments and the file exists there).