R
Railwayβ€’16mo ago
Cyko

Files / pictures deleted after a new deploy

Let me explain my problem When my API ( nodejs ) is deployed online, from my front end I can add images that will be saved on the server with MULTER / FS. The problem is that if I publish code again on github railway, my api will be redeployed and I'll lose the images I've inserted. (when the api is online ) If anyone has already encountered this problem Thanks
20 Replies
Percy
Percyβ€’16mo ago
Project ID: 6fbd9afc-0438-4412-8618-6d138eec245b
Cyko
CykoOPβ€’16mo ago
project ID : 6fbd9afc-0438-4412-8618-6d138eec245b
Brody
Brodyβ€’16mo ago
container storage is not persistent so this is completely to be expected, of you want files to persist you must use a volume
Cyko
CykoOPβ€’16mo ago
oh ok there is an example ?
Brody
Brodyβ€’16mo ago
I have an example that uses node, express and busboy instead of multer, would that use useful?
Cyko
CykoOPβ€’16mo ago
yes πŸ™‚
Brody
Brodyβ€’16mo ago
it's super basic, just has some endpoints for uploading, reading, listing files, deleting files, and serving the files
Cyko
CykoOPβ€’16mo ago
just what I need
Brody
Brodyβ€’16mo ago
https://github.com/brody192/busboy-file-uploads if you have any questions about the code, feel free to ask
Cyko
CykoOPβ€’16mo ago
Thank you πŸ˜‰
Brody
Brodyβ€’16mo ago
nothing is commented since this was just a quick thing I threw together, it doesn't use any of the best practices like file size validation, good name sanitization, etc
Cyko
CykoOPβ€’16mo ago
no worries, I'll try to adapt it with multer and if not, I'll switch to busboy.
Brody
Brodyβ€’16mo ago
when running locally it will save files to ./files in your project folder when running on railway it will automatically use the volume I should probably whip up a multer example too now that I think about it, you aren't the first one to come to help and use multer
Cyko
CykoOPβ€’16mo ago
i have to add the same name to my volume of not necessary ?
Brody
Brodyβ€’16mo ago
it doesn't matter where you mount the volume, the code will automatically pick up the mount point, but personally I like to mount it to /data
Cyko
CykoOPβ€’16mo ago
Okay, I'll give it a try and if I have any questions I'll get back to you
Brody
Brodyβ€’16mo ago
Cyko
CykoOPβ€’16mo ago
Regarding the railwayVolumeMountPath in my .env I just have to add = '/data '?
Brody
Brodyβ€’16mo ago
no thats added automatically for you by railway
Cyko
CykoOPβ€’16mo ago
oh ok πŸ™‚
Want results from more Discord servers?
Add your server