express-admin-examples icon indicating copy to clipboard operation
express-admin-examples copied to clipboard

Is there a way to use dynamic upload path?

Open StarveTheEgo opened this issue 6 years ago • 5 comments

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

StarveTheEgo avatar Jan 13 '19 15:01 StarveTheEgo

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.

simov avatar Jan 13 '19 16:01 simov

Okay, thank you! :) I thought the solution was going to be complex, but seems like preSave can handle my needs Sorry for spam :D

StarveTheEgo avatar Jan 13 '19 17:01 StarveTheEgo

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.

simov avatar Jan 13 '19 17:01 simov

Ok, looks like actual file upload happens before preSave

StarveTheEgo avatar Jan 14 '19 22:01 StarveTheEgo

Yes, you are correct, so it seems that my idea was to augment only the record storing, not the file storing.

simov avatar Jan 14 '19 22:01 simov