Hello,
Having some trouble setting up some volumes for production, as I’m trying to store user logo’s locally. I sort of did what this thread said to do This
But I can’t seem to find where the images end up. Heres my code:
def handle_event("update_logo", params, socket) do
# update user with new logo URL
%{"user" => params} = params
logo_location =
consume_uploaded_entries(socket, :logo, fn meta, entry ->
dest =
Path.join([
"uploads",
"#{socket.assigns.current_user.id}#{Path.extname(entry.client_name)}",
])
File.mkdir_p!(Path.dirname(dest))
File.cp!(meta.path, dest)
url_path = static_path(socket, "/uploads/#{Path.basename(dest)}")
{:ok, url_path}
end)
And my fly.toml:
[mounts]
source="quartz_volume"
destination="/uploads"
And in endpoint.ex:
plug Plug.Static,
at: "/uploads",
from: "/uploads"
I ssh into my app and look around but can’t find them. The volumes are attached to the machines. Any help will be appreciated!
Is it just that you can’t find the directory or they aren’t being served? It should be at /uploads
in the top level /
of your machine.
Not being served? I can now see the folder being created in the machine but when i cd into uploads and hit ls, is says “lost+found”
I meant like were you able to upload the files and see them in your app but just not know where they were on the server, but it sounds like they aren’t making it onto the server as ya, there would be lost+found
subdir, so that’s the one.
The only real difference from your app vs what my own app is doing is that I mounted my volume at /app/uploads
. Not sure why that would make a difference unless there is some permissions prevent writes to anything outside of app
? I’m just grasping at straws here because otherwise your code and config looks almost identical to mine. Since you’re using File.cp!
is your app crashing on upload? I’d check the logs to see if anything is there (if you haven’t already).
Nah, can’t see them in my app just 404. I changed mine to /app/uploads and having the same issue. The directory gets created but the upload doesn’t make it there
It doesn’t crash when I upload a logo either
Really strange. Not sure, then. It might be somewhere else. I’d check that it’s even hitting that consume_uploaded_entries
function. Maybe there is something glaringly obvious I’m missing but it’s otherwise a mystery to me!
In my endpoint.ex i still have the default:
plug Plug.Static,
at: "/",
from: :quartz,
gzip: false,
only: QuartzWeb.static_paths()
as well ass the:
plug Plug.Static,
at: "/uploads",
from: "/app/uploads"
Does that matter? Because I’m still using assets from priv/static/images
Oh right, lol, so a big difference is that I have paths configured per environment:
# dev.exs
config :my_app, :uploads_dir, Path.join([:code.priv_dir(:my_app), "uploads"])
# prod.exs
config :my_app, :uploads_dir, "/app/uploads"
Then this line:
dest =
Path.join([
"uploads",
"#{socket.assigns.current_user.id}#{Path.extname(entry.client_name)}",
])
would be become:
dest =
Path.join([
Application.get_env(:my_app, :uploads_dir),
"#{socket.assigns.current_user.id}#{Path.extname(entry.client_name)}",
])
Progress! So the real difference was that my dest was uploads/x.png but is suppose to be /app/uploads.png!
Now the image is there! BUT my plug might not be working properly as my src is src=“/uploads/x.png” and the plug should be getting it from /app/uploads/x.png right?
Yep, that’s right. Your plug looks fine to me. The only different thing I have is gzip: false
.
1 Like
Okay, so not sure which of the two changes fixed it, but i moved the plug from the bottom of endpoint.ex to just underneath the other Plug.Static, and added gzip: false, and now everything seems to be working !
Thanks heaps for your help!
1 Like