ngx-file-drop
ngx-file-drop copied to clipboard
How can i await for file to upload so i can upload next image with params
How to use with async await to upload images because i want to send params to next image returned from 1st request.
post_id returned from 1st request should be sent with all next images.
this is what is am doing but it is not waiting:
dropped(files: NgxFileDropEntry[]) {
this.files = files;
for (const droppedFile of files) {
// Is it a file?
if (droppedFile.fileEntry.isFile) {
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
fileEntry.file(async (file: File) => {
// Here you can access the real file
console.log(droppedFile.relativePath, file);
await new Promise((resolve, reject) => {
this.http.uploadImages(file, 'UploadImage', this.postId).subscribe((res: any) => {
if (res.status == true) {
resolve(true);
this.postId = res.data.post_id; // i want to send this ID in next request.
} else {
reject();
console.log(res.message);
}
})
});
});
} else {
// It was a directory (empty directories are added, otherwise only files)
const fileEntry = droppedFile.fileEntry as FileSystemDirectoryEntry;
console.log(droppedFile.relativePath, fileEntry);
}
}
}