I'm exploring the process of sending a file uploaded from the UI (angular) to a .NET web service in order for it to parse a CSV file and create a list of objects.
My current understanding of the logic flow is:
File upload ---> Web Service (parse file) --> Web API ---> Database
Does this seem correct?
What steps am I overlooking in terms of sending the file to the service and then to the API Controller?
HTML:
<input type="file" (change)="onFileSelected($event)">
<button type="submit" (click)="onUpload" class="button">Upload</button>
Web service:
static void Main(string[] args)
{
string currentDirectory = Directory.GetCurrentDirectory();
DirectoryInfo directory = new DirectoryInfo(currentDirectory);
var fileName = Path.Combine(directory.FullName, "sample-data.csv");
var fileContents = ReadMonitoredEvent(fileName);
}
public static string ReadFile(string fileName)
{
using (var reader = new StreamReader(fileName))
{
return reader.ReadToEnd();
}
}
public static List<MonitoredEvent> ReadMonitoredEvent(string fileName)
{
var monitoredEventResults = new List<MonitoredEvent>();
// Logic for parsing the CSV file and creating objects...
}
I currently do not have any controller or TypeScript code implemented.
My goal is to enable a user-uploaded file to ultimately result in all created objects being stored in the database.