R
Railwayβ€’2y ago
leaf

Best practice for uploading images or files - React + Express stack

Hi there, a bit of a noob and maybe silly question (and I could not find a a resource that discussed this) but is there a best practice for where and to upload images using React+Express+Railway? My folder structure is:
πŸ“‚ client/
|_ {React frontend code is here ...}
|_ πŸ“ build/
|_ πŸ“‚ public/
|_ πŸ“‚ avis/
|_ {user uploaded jpg files stored here}

πŸ“‚ server/
|_ {server code is here ...}
πŸ“‚ client/
|_ {React frontend code is here ...}
|_ πŸ“ build/
|_ πŸ“‚ public/
|_ πŸ“‚ avis/
|_ {user uploaded jpg files stored here}

πŸ“‚ server/
|_ {server code is here ...}
Right now, when someone uploads a file, it is saved in /client/public/avis. While this works in dev, I realized it doesn't work in prod since I need to make a build each time I want the new pics to be actually uploaded. My proposed solution is that I instead save the files in /client/build/avis/ but I am a bit unsure of this for the following reasons: 1. I don't know if I can persist the data between the railway container(?) and my local machine if I want to make changes to the code 2. I anticipate that then making changes in the dev environment would get a bit sloppy, conceptually speaking because I will now need to manage assets between /client/public/ and /client/build/ . It just seems... wrong? What is the best practice of where to store images that users can upload in a React+Express+Railway stack?
5 Replies
Percy
Percyβ€’2y ago
Project ID: N/A
Percy
Percyβ€’2y ago
The best practice for uploading images in a React+Express+Railway stack is to store them in the /client/build/avis/ directory.
⚠️ experimental feature
leaf
leafOPβ€’2y ago
N/A
Finn
Finnβ€’2y ago
The FS is wiped between deploys you will need to use an external storage service like s3
leaf
leafOPβ€’2y ago
ok cool, thx!!
Want results from more Discord servers?
Add your server