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:
My nixpacks.toml file [phases.build] cmds = ['npm run build', 'php artisan optimize:clear','php artisan storage:link']...
Jump to solution
41 Replies
Percy
Percy5mo ago
Project ID: 17cc2546-a50b-4c61-b4e2-f665e56c4750
Brody
Brody5mo ago
413 or something right?
cloudkasalu
cloudkasalu5mo ago
yes so it seens
Brody
Brody5mo ago
can you confirm the error code for me?
cloudkasalu
cloudkasalu5mo ago
my deployment log shows
No description
Brody
Brody5mo ago
i mean when you try to upload an image
cloudkasalu
cloudkasalu5mo ago
the form goes through and i get that error in the logs when the image tries to render
Brody
Brody5mo ago
please review the network logs in the dev tools during an image upload
cloudkasalu
cloudkasalu5mo ago
there is no error during the upload only a 404 when there image is attempted to be previewed
Brody
Brody5mo ago
where are you saving the image?
cloudkasalu
cloudkasalu5mo ago
storage/app/public/
Brody
Brody5mo ago
are you using a volume?
cloudkasalu
cloudkasalu5mo ago
no
Brody
Brody5mo ago
you definitely want to be, otherwise your images wont persist between deployments https://docs.railway.app/guides/volumes
cloudkasalu
cloudkasalu5mo ago
how do i set it up with laravel
Brody
Brody5mo ago
you save the files to the volume during upload
cloudkasalu
cloudkasalu5mo ago
in my code i use Storage::put(public/...) to store files, so do i have to mount my volume to /public ?
Brody
Brody5mo ago
try mounting the volume to /app/storage/uploads and then save the images to ./storage/uploads
cloudkasalu
cloudkasalu5mo ago
laravel file system looks like app/storage/app/public
Brody
Brody5mo ago
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
cloudkasalu
cloudkasalu5mo ago
have found the issue to be that when building the server is not running php artisan storage:link
Brody
Brody5mo ago
you would still need a volume no matter what, otherwise any file you uploaded is wiped when you make the next deployment
cloudkasalu
cloudkasalu5mo ago
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
Brody
Brody5mo ago
it would be far better for you to define these kinds of things in a nixpacks.toml file https://nixpacks.com/docs/configuration/file
cloudkasalu
cloudkasalu5mo ago
am finding it difficult to apply this
Brody
Brody5mo ago
let's see what you have so far
lowzyyy
lowzyyy5mo ago
I already have some images in the folder. Does adding volume on that path destroy everything that is already there?
Brody
Brody5mo ago
that's correct, volumes are not mounted as overlays
lowzyyy
lowzyyy5mo ago
How can i manually put something in that folder from my PC?
Brody
Brody5mo ago
all volume access has to be done via the service it's attached to
cloudkasalu
cloudkasalu5mo ago
[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
Brody
Brody5mo ago
why do you think that?
cloudkasalu
cloudkasalu5mo ago
beacuse its not linking the storage
Brody
Brody5mo ago
does the build table at the top of the build logs reflect correctly with what you have set there?
cloudkasalu
cloudkasalu5mo ago
it looks like it doesnt
Brody
Brody5mo ago
did you name the file correctly? nixpacks.toml
cloudkasalu
cloudkasalu5mo ago
have named the file correctly and now the app as failed to build Error: Failed to parse Nixpacks config file nixpacks.toml
Brody
Brody5mo ago
you dont need to specify every phase, just the phase you want to change
Solution
cloudkasalu
cloudkasalu5mo ago
My nixpacks.toml file [phases.build] cmds = ['npm run build', 'php artisan optimize:clear','php artisan storage:link']
cloudkasalu
cloudkasalu5mo ago
the storage is now linked, thank you
Brody
Brody5mo ago
no problem!