This is the code of my backend controller (asp.net core 3.1)
my front end code (angularJS)
my team has decided that we will upload the path of the these images stored in this folder in database, and later we will be uploading images in a different way. The main thing that we are stuck on is how to actually store these images path in database?
this is the code for my uploadimage button. We just need to store the path of the images in database, can someone help me here?
2
Answers
You’ve done the hard bit already as you have the variable filepath already set.
Do you have a database already set up to post to? If so it will just be a case of calling your dbcontext.Add(filepath) to add to the database. Otherwise you’ll need to get setup which is out of scope of the question.
I would create a model with some sort of identifier, and then the filepath to make it easier to track down later.
You can try to use EFcore to add data to database,here is a simple demo:
Your Controller:
model:
YourContext:
Configuration:
appsettings.json:
For more details,you can refer to the official doc.