Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to use dynamic upload path? #16

Open
StarveTheEgo opened this issue Jan 13, 2019 · 5 comments
Open

Is there a way to use dynamic upload path? #16

StarveTheEgo opened this issue Jan 13, 2019 · 5 comments

Comments

@StarveTheEgo
Copy link

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

@simov
Copy link
Owner

simov commented Jan 13, 2019

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.

@StarveTheEgo
Copy link
Author

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

@simov
Copy link
Owner

simov commented Jan 13, 2019

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.

@StarveTheEgo
Copy link
Author

Ok, looks like actual file upload happens before preSave

@StarveTheEgo StarveTheEgo reopened this Jan 14, 2019
@simov
Copy link
Owner

simov commented Jan 14, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants