So, i have a system set up to be able to upload files via Angular to NestJS, but i wanna know the progress of the upload, because its a little annoying that i cant see when it finishes.
Is there any way to do it? Thanks!
Heres my code:
FrontEND: Angular:
let formData = new FormData()
let dateX = cur_day + hours + minutes + seconds; // removed the vars
formData.append("dest", `${this.chatid}/${this.userData.userid}/${dateX}/`)
this.draftImages.forEach((fileData: any) => {
formData.append("file", fileData.file, fileData.name)
console.log(fileData.file);
})
console.log(formData)
this.http.post<any>("http://localhost:3000/chat/message/dm/uploadImg", formData).subscribe((result) => {
console.log(result, formData)
let filesUploaded: any = []
this.draftImages = []
Array.from(result).forEach((file: any) => {
filesUploaded.push(file.destination + file.originalname)
})
this.dmService.sendMessage({
message: message,
chatid: this.chatid,
userid: this.userData.userid,
username: this.userData.username,
pfp: this.userData.pfp,
files: filesUploaded
});
})
BackEND: NestJS:
@Post("uploadImg")
@UseInterceptors(
AnyFilesInterceptor({
storage: diskStorage({
destination: function (req: any, file, cb) {
console.log(file);
function mkdirRecursiveSync(path: string) {
if (!existsSync(path)) {
mkdirRecursiveSync(dirname(path));
mkdirSync(path);
}
}
const destPath = `CDN/attachments/${req.body.dest}`;
mkdirRecursiveSync(destPath);
console.log(req.body)
cb(null, destPath);
},
filename: function (req, file, cb) {
console.log(file)
cb(null, file.originalname);
},
}),
})
)
async uploadedFile(@UploadedFiles() file) {
console.log(file)
return file;
}