Am unable to upload images with laravel app
Project ID: 17cc2546-a50b-4c61-b4e2-f665e56c4750
This is first time using laravel for backend on railway, when i attempt to upload an image it seems to get destroyed, like i do not have permission to do so
Solution:Jump to solution
My nixpacks.toml file
[phases.build]
cmds = ['npm run build', 'php artisan optimize:clear','php artisan storage:link']...
41 Replies
Project ID:
17cc2546-a50b-4c61-b4e2-f665e56c4750
413 or something right?
yes so it seens
can you confirm the error code for me?
my deployment log shows
i mean when you try to upload an image
the form goes through and i get that error in the logs when the image tries to render
please review the network logs in the dev tools during an image upload
there is no error during the upload
only a 404 when there image is attempted to be previewed
where are you saving the image?
storage/app/public/
are you using a volume?
no
you definitely want to be, otherwise your images wont persist between deployments
https://docs.railway.app/guides/volumes
how do i set it up with laravel
you save the files to the volume during upload
in my code i use Storage::put(public/...) to store files, so do i have to mount my volume to /public ?
try mounting the volume to
/app/storage/uploads
and then save the images to ./storage/uploads
laravel file system looks like app/storage/app/public
it was only a suggestion based on what has worked for other people in the past, you are free to mount the volume to whatever path works best for you
have found the issue to be that when building the server is not running php artisan storage:link
you would still need a volume no matter what, otherwise any file you uploaded is wiped when you make the next deployment
yes, the issue am now facing is with the NIXPACKS_BUILD_CMD env values
it seems when i add multiple build commands i run into a build error, i tried adding "NIXPACKS_BUILD_CMD =npm run build && php artisan storage:link" just to confirm that the php artisan storage:link was the issue and the images did show, but other commands are not executed, when i added all the necessary build commands i run into an error
when i remove the env everything is added except the php artisan storage:link
it would be far better for you to define these kinds of things in a nixpacks.toml file
https://nixpacks.com/docs/configuration/file
am finding it difficult to apply this
let's see what you have so far
I already have some images in the folder. Does adding volume on that path destroy everything that is already there?
that's correct, volumes are not mounted as overlays
How can i manually put something in that folder from my PC?
all volume access has to be done via the service it's attached to
[phases.setup]
nixPkgs = ['php' 'nodejs' 'composer']
[phases.install]
cmds = ['composer install', 'npm install']
[phases.build]
cmds = ['npm run build', 'php artisan optimize:clear']
[start]
cmd = 'php artisan storage:link'
it looks like its totally ignoring the file when building
why do you think that?
beacuse its not linking the storage
does the build table at the top of the build logs reflect correctly with what you have set there?
it looks like it doesnt
did you name the file correctly? nixpacks.toml
have named the file correctly and now the app as failed to build
Error: Failed to parse Nixpacks config file
nixpacks.toml
you dont need to specify every phase, just the phase you want to change
Solution
My nixpacks.toml file
[phases.build]
cmds = ['npm run build', 'php artisan optimize:clear','php artisan storage:link']
the storage is now linked, thank you
no problem!