A question about onUploadsCleared

I would like to define a send message to execute the onUploadsCleared event which associated with the file upload component.

May I know how to do that?

Thank you

You can’t invoke component extension methods yourself.

In 8.1.18 you’ll be able to invoke a clearUploads() scripting function manually, if that’s what you’re trying to do:

And to clarify, onUploadsCleared is an Event, which means it is triggered by some sort of user interaction or change in component state. Events may not be invoked or requested by scripting. If your goal is to reset the state of the component such that it is not displaying any sort of summary of past upload attempts, then the aforementioned clearUploads() component function will indeed be what you want to use.

You would do so like this, although you might need to adjust the path if the triggering script’s source is not a sibling component.

self.getSibling("FileUploadComponentNameHere").clearUploads()

Note that this is a component function, which can of course be invoked from any reasonably-scoped script.

Thank you all reply. I wrote some codes onUploadsCleared, and called it from cancel button and submit button , it works for what I have written , but can’t deleted the file has been uploaded , unless I click on the clear button which I highlighted on the screenshot , it brings bug to me , as I want when I click on cancel or submit button , the uploaded file can be deleted and allows me to upload a file again , the max upload is one . may I know how to delete the event .file which defined on onUploadsCleared
image

The clearUploads() function does nothing more than reset the appearance of the component. If you want to manipulate or delete files you have uploaded then you must handle that with your own code because the component has no idea where you placed the files you’ve uploaded.

This is what I use to delete files I’ve uploaded through the File Upload component:

    from java.io import File
	text = self.getSibling('TextField_0').props.text
	expected_upload_path = 'data/' + text
	completed = File(expected_upload_path).delete()
    # the 'completed' variable can be used for reporting the success of the deletion.

This of course assumes that the File Upload is SAVING/WRITING directly to the data directory.

May I know how to reset the appearance of the Fileupload component after the upload is finished . I added the clearUploads() function within the script, It doesn’t seem to work. Is there any possible way to automatically reset the fileupload component’s appearance once the upload is finished.?

What version of Ignition are you using? The clearUploads function was introduced in 8.1.18, so you need to be using that version or newer. If you are indeed using a valid version, you might need to delay the reset via an asynchronous call. The function was intended to be something invoked after files had been uploaded, and if it is invoked while the files are being processed and the UI updated there could be a race condition at play.

Could you verify your version and provide your code here?

I am using the latest version 8.1.18
The code I used to upload the files was:
FileName=event.file.name
Filedata=event.file.getBytes()
System.db.runNamedQuery(“Namedquery”,[FileName,FileData])

I am not sure how to include the clearUploads() function after this.

self.clearUploads()

I tried self.clearUploads(),
There is no error & also the appearance still shows the previous upload summary.

"""
This is all pseudo-code, but you mght need to wait some period of time to
avoid a race-condition with the browser manipulating the UI. Also, I 
recommend AGAINST using clearUploads in this area because this
executes for every file you upload. The function has undefined behavior
when operating on the component in-between file operations. 
"""
def wait_and_reset(component = self):
    from time import sleep
    sleep(2)
    component.clearUploads()

FileName=event.file.name
Filedata=event.file.getBytes()
System.db.runNamedQuery(“Namedquery”,[FileName,FileData])
system.util.invokeAsynchronous(wait_and_reset)