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