express-admin-examples
express-admin-examples copied to clipboard
Is there a way to use dynamic upload path?
Hello! I would like to have dynamic file upload path, because if i will upload all the files into one directory, it will lead to problems, due to large amount of files.
How can i easily (or not) make express-admin to get upload path as a function result?
The example is - songs library, including mp3/wav/etc/etc for my radio I would like to store all the files i upload in the directories like {artist_id}/{album_id}/{track_name}.{ext}
And when i would edit any existing entry in my database, i'd love to make express-admin to seek file in that dynamic directory path
Thanks foward :-) I am relatively new to GitHub, but experienced programmer
There is a preSave hook available. Put a debugger
breakpoint inside it, and run your server with --inspect-brk
to see what comes in as data from the admin. I think that'd be your best shot.
Okay, thank you! :) I thought the solution was going to be complex, but seems like preSave can handle my needs Sorry for spam :D
You'll have to dynamically update the path that the multipart middleware is using to store the files. The actual file upload is handled by the multipart middleware.
Ok, looks like actual file upload happens before preSave
Yes, you are correct, so it seems that my idea was to augment only the record storing, not the file storing.