# A question about onUploadsCleared

**URL:** <https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262>\
**Category:** Ignition\
**Created:** [June 1, 2022, 3:10pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262 "2022-06-01T15:10:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mary\_Zheng](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Mary\_Zheng](https://forum.inductiveautomation.com/u/Mary_Zheng)\
**Post date:** [June 1, 2022, 3:10pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/1 "2022-06-01T15:10:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 1, 2022, 3:36pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/2 "2022-06-01T15:36:32Z")

</div>

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:

> [@Nightly 8.1 Changelogs - 2022](https://forum.inductiveautomation.com/t/nightly-8-1-changelogs-2022/54636/81):
>
> Nightly Changelog: 8.1.18-b20220524 Perspective 3351: File Upload: Implement clearUploads() component method Added clearUploads() script function to the FileUpload Component. Platform 5392: Add formatting pattern / replacement tokens for manual and scheduled backup filename generation Scheduled backups (as well as manually downloaded backups) now feature a customizable filename pattern with optional placeholders such as ${os}, ${version}, ${gatewayName}, ${edition} and ${timestamp}.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [June 1, 2022, 4:03pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/3 "2022-06-01T16:03:48Z")

</div>

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.

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

```

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

---

<div class="post-metadata">

**Author:** ![Mary\_Zheng](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Mary\_Zheng](https://forum.inductiveautomation.com/u/Mary_Zheng)\
**Post date:** [June 2, 2022, 12:44pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/4 "2022-06-02T12:44:12Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/1/d185958726f0644b82abd09aadce11a51289ec6b.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [June 2, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/5 "2022-06-02T16:14:25Z")

</div>

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:

```auto
    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.

---

<div class="post-metadata">

**Author:** ![S\_ANIL\_KUMAR](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@S\_ANIL\_KUMAR](https://forum.inductiveautomation.com/u/S_ANIL_KUMAR)\
**Post date:** [July 5, 2022, 8:26am UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/6 "2022-07-05T08:26:32Z")

</div>

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.?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 5, 2022, 3:20pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/7 "2022-07-05T15:20:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![S\_ANIL\_KUMAR](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@S\_ANIL\_KUMAR](https://forum.inductiveautomation.com/u/S_ANIL_KUMAR)\
**Post date:** [July 5, 2022, 3:34pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/8 "2022-07-05T15:34:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 5, 2022, 3:39pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/9 "2022-07-05T15:39:43Z")

</div>

`self.clearUploads()`

---

<div class="post-metadata">

**Author:** ![S\_ANIL\_KUMAR](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@S\_ANIL\_KUMAR](https://forum.inductiveautomation.com/u/S_ANIL_KUMAR)\
**Post date:** [July 5, 2022, 3:44pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/10 "2022-07-05T15:44:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 5, 2022, 5:33pm UTC](https://forum.inductiveautomation.com/t/a-question-about-onuploadscleared/60262/11 "2022-07-05T17:33:51Z")

</div>

> [@cmallonee](#):
>
> If you are indeed using a valid version, you might need to delay the reset via an asynchronous call

```auto
"""
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)

```
