# Invoking file upload event by button

**URL:** <https://forum.inductiveautomation.com/t/invoking-file-upload-event-by-button/83967>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [January 9, 2024, 2:15pm UTC](https://forum.inductiveautomation.com/t/invoking-file-upload-event-by-button/83967 "2024-01-09T14:15:13Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Subin\_Adhikari](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Subin\_Adhikari](https://forum.inductiveautomation.com/u/Subin_Adhikari)\
**Post date:** [October 7, 2026, 2:33pm UTC](https://forum.inductiveautomation.com/t/invoking-file-upload-event-by-button/83967/8 "2026-10-07T14:33:57Z")

</div>

Since I absolutely needed this I had to inject JS. use this post as a reference

> [@Perspective Table Context Menu - activated rowData](https://forum.inductiveautomation.com/t/perspective-table-context-menu-activated-rowdata/96051/13):
>
> Since I absolutely needed this right now, was able to do it via following code. prop\_name = "selected\_row" #this is the page custom property to write value to. code = """\<img style='display:none' src='/favicon.ico' onload=\" const view = [...window.\_\_client.page.views.\_data.values()].find(v =\> v.value.mountPath == this.parentNode.parentNode.parentNode.getAttributeNode('data-component-path').value.split('.')[0]).value; const tableId = '#"""+str(value)+"""'; let highlightedRow = null; function se…

The code to invoke, file upload from a button would be.

```
code = """<img style='display:none' src='/favicon.ico' onload="
    const eventButton = document.getElementById('btn_import');
    if (eventButton) {
        eventButton.addEventListener('click', function() {
            const file_upload_component = document.getElementById('import_file');
            if (file_upload_component) {
                file_upload_component.click();
            }
        });
    }
"></img>""".replace("\\n", "").replace("\\t", "")

return code

```

Make sure to add a domId ( [Please add ids to perspective components for writing tests - #2 by ggross](https://forum.inductiveautomation.com/t/please-add-ids-to-perspective-components-for-writing-tests/46949/2) ) to both the component.

Above function used btn\_import as a button and import\_file as a file upload domId.

![file_import_with_button](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c615f1d6f6ff70c6f489f87960ca6c80d1311bb.gif)

Better way to do would be [Perspective Table Context Menu - activated rowData - #14 by nminchin](https://forum.inductiveautomation.com/t/perspective-table-context-menu-activated-rowdata/96051/14) after IA Stops the Injecting.

---

_[View the full topic](https://forum.inductiveautomation.com/t/invoking-file-upload-event-by-button/83967)._
