Writing permission
Hello! I'm new to Railway and have a question about how to change writing permission on a folder. My project is a Laravel API. I have created the folder 'uploads' in the 'public' folder. When an image is sent with POST to the API the controller moves the file to the folder 'uploads'. This works fine locally but with my API deployed to Railway I get an error message saying "Unable to write in the "/app/public/uploads" directory." How can I change the writing permission on my folder 'uploads'? Grateful for any help!
9 Replies
Project ID:
N/A
you would want to use a volume for this https://docs.railway.app/reference/volumes
mount the volume to
/app/storage
then you can save your files to /app/storage/uploads
It didn't work. I created the volume, connected it to the service, mounted it to /app/storage and used the environment variables RAILWAY_VOLUME_NAME=storage and RAILWAY_VOLUME_MOUNT_PATH=/storage.
I still get status 500 and the message "message": "Unable to write in the "/app/public/uploads" directory."
Any solutions, please?
those variables are set automatically for you, please remove them from your service variables
in your code you should be saving files to
/app/storage/<a subfolder of your choosing>
when on railwayDo I have to change this code in my Laravel controller?
$image->move(public_path('uploads'), $imageName);
^
Like this?
$image->move(public_path('/app/storage/uploads'), $imageName);
I'm sorry I don't know php, I'm just telling you what needs to be done, it is your task to apply it to the language you are using
Ok, thanks!