R
Railway•10mo ago
sara!khan

everytime i deploy my image file that i was uploaded is missing

i use filesystem to save my all images. But when i deploy again my file is gone all of the product i have upload is left me just only text.. I think because of the old one would be delete after new deploy And how should i handle this ? Use another file system ?
Solution:
The files in your deployment is ephemeral, so it's not possible to store persistent files that way to store persistent files on Railway, you'd want to use a volume...
Jump to solution
22 Replies
Percy
Percy•10mo ago
Project ID: b84d9bbc-534d-4917-ae24-79121d6fb78b
sara!khan
sara!khan•10mo ago
b84d9bbc-534d-4917-ae24-79121d6fb78b
Solution
Fragly
Fragly•10mo ago
The files in your deployment is ephemeral, so it's not possible to store persistent files that way to store persistent files on Railway, you'd want to use a volume
sara!khan
sara!khan•10mo ago
i have config mount volume in railway setting and fill more 2 varibles follow the docs and try with upload new image size 3Mb and go back to check size in volume's metric from my setting in project is when i have upload the file it will upload to 'media' folder and i config in payload volume path is '/media' is i correctness config ?
sara!khan
sara!khan•10mo ago
this is my config
No description
Fragly
Fragly•10mo ago
Yea, keep in mind though that the /media folder is not in your app's root by default I recommend you use RAILWAY_VOLUME_MOUNT_PATH service variable to get the path of your /media folder
sara!khan
sara!khan•10mo ago
i try all day but still the same with it unmount sir. when i try to redeploy all the file is gone again
No description
sara!khan
sara!khan•10mo ago
i try first with '/media' because all the file will save in media folder second i try with '/app/media' still same result third i try with '/app' deploy was crashed
Fragly
Fragly•10mo ago
nah nah, Railway provides the RAILWAY_VOLUME_MOUNT_PATH themselves, you're not supposed to write that into service variables
sara!khan
sara!khan•10mo ago
okay one last question ;-;) in my code i executed code to save upload files to folder 'media' and i mount in railway to '/app/media' it didn't mean these two directory will sync together when i redeploy and didn't mean the file i have upload will save in mount volume correct right ? --- sorry for my bad english, i try so hard to understand both of english and railway sir
Fragly
Fragly•10mo ago
No problem at all 🙂 If you write a file to RAILWAY_VOLUME_MOUNT_PATH then it'll store that file in your Volume, this Volume is attached to the docker container when the docker container starts, the volume and its contents will remain intact until you delete it Meaning to say, anything you write to RAILWAY_VOLUME_MOUNT_PATH will stay there and your application will be able to access it, all the files will remain there unless you delete them, naturally ( by the way, i say write to RAILWAY_VOLUME_MOUNT_PATH only out of principal since it's better to the path the service variable gives than just a hardcoded path, but it should work fine the way you have it )
sara!khan
sara!khan•10mo ago
Aowwww i got it !
tansan
tansan•4mo ago
Is that app root always /app ?
Fragly
Fragly•4mo ago
if built with nixpacks, yes
Brody
Brody•4mo ago
if built with a dockerfile, it would be whatever the last workdir set it to
Duchess
Duchess•3mo ago
New reply sent from Help Station thread:
I cannot find RAILWAY_VOLUME_MOUNT_PATH in the "Variables" section, as shown in the attachment. Is there any way to ensure that this env variable has been set right? (when I tried to add it, a pop-up warning message appeared, so I refrained afraid to mess things it up)I am trying to save files there with the following nodeJS statement: path.join(process.env.RAILWAY_VOLUME_MOUNT_PATH || "./", "db") and it still doesn't work (the files are removed after new deployments)Is there any way, at least, to see what's going on the machine disk? I wanna know whether files are saved in ./db or RAIL.../db.I've already modified the start command, using nixpacks.toml file, to: RAILWAY_VOLUME_MOUNT_PATH=$RAILWAY_VOLUME_MOUNT_PATH pnpm start
You're seeing this because this thread has been automatically linked to the Help Station thread.
Brody
Brody•3mo ago
you should not be setting that variable anywhere, that variable is automatically available to your code.
Duchess
Duchess•3mo ago
New reply sent from Help Station thread:
I see. Still, I cannot access that variable via process.env in nodeJS. I'm trying to figure out why.
You're seeing this because this thread has been automatically linked to the Help Station thread.
Brody
Brody•3mo ago
probably because you are overwriting it somewhere
Duchess
Duchess•3mo ago
New reply sent from Help Station thread:
Pretty sure I'm not. I guess I should first add it in the docker file config, using advantage of it's interpolation:web:environment:- RAILWAY_VOLUME_MOUNT_PATH=${RAILWAY_VOLUME_MOUNT_PATH}This's my first time using docker and nixpacks. I'm jumping around between documentations right now.
You're seeing this because this thread has been automatically linked to the Help Station thread.
Brody
Brody•3mo ago
Please stop trying to set it somewhere, you are overwriting it
Duchess
Duchess•3mo ago
New reply sent from Help Station thread:
Tell me where I'm overwriting it!See the attachment in my previous reply.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Right there in the cmd.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
This is not overwriting; I'm trying to pass it through a chain of local environments. Even though, if you consider it as overwriting, It doesn't change anything (it overwrites to the same value). Overwriting x to x, for instance, wouldn't change the value of x.Furthermore, I've removed it from the toml file. And added the following if statement, as shown in the first attachment:const RAILWAY_PATH = process.env.RAILWAY_VOLUME_MOUNT_PATH; if (!RAILWAY_PATH || RAILWAY_PATH === '') { console.warn('RAILWAY_VOLUME_MOUNT_PATH undefined.'); }The second attachment, however, shows the deploy logs from railway.app dashboard.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
If you are unable to find out where you are overwriting it you can instead simply use the volume path you set in railway in code.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
This is not overwriting; I'm trying to pass it through a chain of local environments. Even though, if you consider it as overwriting, It doesn't change anything (it overwrites to the same value). Overwriting x to x, for instance, wouldn't change the value of x.Furthermore, I've removed it from the toml file. And added the following if statement, as shown in the first attachment:const RAILWAY_PATH = process.env.RAILWAY_VOLUME_MOUNT_PATH; if (!RAILWAY_PATH || RAILWAY_PATH === '') { console.warn('RAILWAY_VOLUME_MOUNT_PATH undefined.'); }The second attachment, however, shows the deploy logs from railway.app dashboard.I've sent the first one wrong by mistake. Here the right one.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
If you are unable to find out where you are overwriting it you can instead simply use the volume path you set in railway in code.The thing is... that I didn't, and I'm definitely not overwriting it. It's not available in the code. It's undefined in process.env.
You're seeing this because this thread has been automatically linked to the Help Station thread.
Want results from more Discord servers?
Add your server