I have a NodeJS server running as a file storage for clients and other services.
I am using two approach to organize when a file is uploaded:
1, Prefix the folder that file belongs to, such as: image files will go to uploads/image folder, mp3 files will go to uploads/mp3 folder here is NodeJS implimentation
let image = "public/uploads/image";
let mp3 = "public/uploads/mp3";
let video = "public/uploads/video";
fs.existsSync(image) || fs.mkdirSync(image, { recursive: true });
fs.existsSync(video) || fs.mkdirSync(video, { recursive: true });
fs.existsSync(mp3) || fs.mkdirSync(mp3, { recursive: true });
2, Dynamic organize base on params on the request I have some parameters in the endpoint to config path that file will go to
const savedPath = `public/uploads/${type}/${path}`
fs.existsSync(savedPath) || fs.mkdirSync(savedPath, { recursive: true })
So what is the best way to organize files in a file storage service?
Aucun commentaire:
Enregistrer un commentaire