FileUpload clear pending message on complete -solved

UI Components for React
Post Reply
chrishj
Posts: 229
Joined: 11 Jul 2011, 21:58
Location: England, Lancashire
Contact:

27 Aug 2023, 10:01

Hi,

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}
						/>
						
My Upload hander

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,
		});
	};
I have searched the forum as Google but am not clear on the way to clear this message when the process completes.
Last edited by chrishj on 29 Aug 2023, 08:28, edited 1 time in total.
PrimeReact: 9.6.0
NextJs: 13.4.12
Theme Apollo v9.0
Database pg 8.8.0
react-hook-form: 7.38.0

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

28 Aug 2023, 14:44

See here: https://primereact.org/fileupload/#api. ... hods.clear

You can call "fileUploadRef.current?.clear()` to clear the files from the window.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

chrishj
Posts: 229
Joined: 11 Jul 2011, 21:58
Location: England, Lancashire
Contact:

29 Aug 2023, 08:31

Many thanks - this solution works great!
PrimeReact: 9.6.0
NextJs: 13.4.12
Theme Apollo v9.0
Database pg 8.8.0
react-hook-form: 7.38.0

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests