My challenge involves uploading images before saving a record to a database. I require the upload process to finish completely before the record is saved.
Here is the function responsible for handling image uploads:
async uploadTrainingModule(selectedFiles: any = this.files) {
// Image Upload Process
for (let i = 0; i < selectedFiles.length; i++) {
await this.filesUploaded.push(selectedFiles[i]);
}
}
By utilizing async and await in the above method, my intention was for it to finalize before proceeding with anything else in the subsequent method below (which is responsible for writing to the database):
createTrainingModule() {
this.uploadTrainingModule().then(resp => {
// Database Writing Code Here
})
}
I aim to ensure that the code following the comment only runs AFTER the entire uploadTrainingModule method has completed. However, my current implementation does not seem to achieve this. What alternative approach should I consider?