Hi
I'm trying to use Exfile to serve some images in a phoenix project, but I'm heading some serious head blocks that i'm not sure how to solve.
the path I'm getting for exfile.url or exfile.path serve me a link to a file not found
I'm seeding the file to the database like shown in #33
the db is MySQL
so my setup is as following:
defmodule Myapp.Repo.Migrations.CreateCities do
use Ecto.Migration
def change do
create table(:cities) do
add :name, :string, null: false
add :country, :string, size: 2, null: false
add :image, :string
timestamps()
end
end
end
defmodule Myapp.Web.City do
use Ecto.Schema
import Ecto.Changeset
schema "cities" do
field :name, :string, null: false
field :country, :string, size: 2, null: false
field :image, Exfile.Ecto.File
timestamps()
end
@required_fields ~w(name country image)
def changeset(city, params \\ %{}) do
city
|> cast(params, @required_fields)
|> validate_required([:name, :country])
end
defmodule Myapp.Web.Router do
use NomadRentalPhx.Web, :router
forward "/attachments", Exfile.Router
...
end
config :exfile, Exfile,
secret: "secret string to generate the token used to authenticate requests",
backends: %{
"store" => {Exfile.Backend.FileSystem,
directory: Path.expand("priv/static/store/#{System.system_time}")
},
"cache" => {Exfile.Backend.FileSystem,
directory: Path.expand("priv/static/cache/#{System.system_time}")
}
}
defmodule Myapp.Web do
def view do
quote do
import Exfile.Phoenix.Helpers
end
end
end
image: %Exfile.File{backend: %Exfile.Backend{backend_mod: Exfile.Backend.FileSystem,
backend_name: "store",
directory: "path/myapp/priv/static/store/1493794933541734000",
hasher: Exfile.Hasher.Random, max_size: -1, meta: %{ttl: :infinity},
postprocessors: [], preprocessors: []},
backend_meta: %{absolute_path: "path/myapp/priv/static/store/1493794933541734000/59b376925ac84cb5832c683b7fd1fcaa03f990fffea1a0d24dd9ab49dcbb"},
id: "59b376925ac84cb5832c683b7fd1fcaa03f990fffea1a0d24dd9ab49dcbb",
meta: %{}},
<img src="<%= exfile_url(@conn, city.image, format: "jpg", processor: "limit", processor_args: [1024, 1024]) %>">
<img src="http://localhost:4000/attachments/I2N0-Eo4hFVv75JZHnPrWXsH69yI5hRJNnDi7ikbRoc=/store/limit/1024/1024/47b8cac5c27e9034f4e0a0404aae6cb9df58b568621176b47eba4314a960/file.jpg">
Hi I'm trying to use Exfile to serve some images in a phoenix project, but I'm heading some serious head blocks that i'm not sure how to solve. the path I'm getting for
exfile.url
orexfile.path
serve me a link to a file not foundI'm seeding the file to the database like shown in #33 the db is MySQL
so my setup is as following: