I am using the FileUpload compoent. This loads an XML file and sends the file to the NestJs backend and reports the file upload status successfully using Toast messages.
The issue that I have is that when the upload starts I get a pending message with the file name and status as pending. This message is not cleared upload process completed.
As I am the custom upload method, the issue is probably that I am missing a step.
FileUpload component
Code: Select all
<FileUpload
name="edcStock"
uploadHandler={onUploadHandler}
customUpload
auto
accept="text/xml"
chooseLabel="Select stock file"
maxFileSize={1000000}
/>
Code: Select all
const onUploadHandler = async (event: any) => {
const file = event.files[0];
const filedata = await readXmlFile(file);
const edcJson = await parseXml(filedata);
let numRecs = 0;
for (const product of edcJson) {
try {
const { data } = await axios.post(`/api/admin/edcupload`, product);
numRecs++;
} catch (result: any) {
toast.current?.show({
severity: 'error',
summary: 'Unexpected error',
detail: `Could not save the product ${result.statusText}`,
life: 3000,
});
}
}
toast.current?.show({
severity: 'info',
summary: 'Uploaded',
detail: `EDC stock file uploaded ${numRecs} items`,
life: 3000,
});
};