# Update query for file upload component

**URL:** <https://forum.inductiveautomation.com/t/update-query-for-file-upload-component/87266>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 13, 2024, 1:09pm UTC](https://forum.inductiveautomation.com/t/update-query-for-file-upload-component/87266 "2024-03-13T13:09:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben522326](https://avatars.discourse-cdn.com/v4/letter/b/b4bc9f/32.png) [@Ben522326](https://forum.inductiveautomation.com/u/Ben522326)\
**Post date:** [March 13, 2024, 1:09pm UTC](https://forum.inductiveautomation.com/t/update-query-for-file-upload-component/87266/1 "2024-03-13T13:09:27Z")

</div>

I'm creating a view similar to a form where the user can fill in text fields, select buttons, and upload files. I want to store all this into a database with a 'submit' button click. However I can't figure out how to store the bytes of the file that the user uploaded to database on the submit button click.

I've been able to store the file bytes to the database by itself with the file upload component's onFileReceieved script by using event.file.getBytes(), so I know it's possible. But I want to store the bytes, along with all the other user input, to the database in one query on the submit button click. I can't figure out how to reference the bytes of the file outside of its own event script. How can I accomplish this?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 13, 2024, 2:13pm UTC](https://forum.inductiveautomation.com/t/update-query-for-file-upload-component/87266/2 "2024-03-13T14:13:15Z")

</div>

I think you'll have to do something like write the file to a temp location in onFileReceived, then store that location as a session prop that you can access when the submit button is clicked. You'll have to read the bytes back from that temporary file.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 13, 2024, 2:30pm UTC](https://forum.inductiveautomation.com/t/update-query-for-file-upload-component/87266/3 "2024-03-13T14:30:53Z")

</div>

You might find my `viewVarMap()`, `pageVarMap()`, or `sessionVarMap()` [functions](https://www.automation-pros.com/toolkit/doc/scripting.html#sessionvarmap) helpful for this kind of temporary storage. All part of my Integration Toolkit module.

---

<div class="post-metadata">

**Author:** ![Ben522326](https://avatars.discourse-cdn.com/v4/letter/b/b4bc9f/32.png) [@Ben522326](https://forum.inductiveautomation.com/u/Ben522326)\
**Post date:** [March 13, 2024, 7:13pm UTC](https://forum.inductiveautomation.com/t/update-query-for-file-upload-component/87266/4 "2024-03-13T19:13:02Z")

</div>

This ended up being my solution...

> [@Ignition File Upload Component](https://forum.inductiveautomation.com/t/ignition-file-upload-component/79044/4):
>
> I've had a similar challenge before, where I had a user form for an event log entry with an optional report upload. I got around it by temporarily storing the file in a global variable dictionary in the onFileReceived event: self.custom.fileName = event.file.name system.util.getGlobals()[event.file.name] = event.file.getBytes() That way I could do a single insert query into the database with the form data and file upon form completion. I also had an onShutdown event on the view to clear the gl…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 13, 2024, 7:41pm UTC](https://forum.inductiveautomation.com/t/update-query-for-file-upload-component/87266/5 "2024-03-13T19:41:38Z")

</div>

Oy! Dangerous (easy to screw up the cleariing step), and will have clashes when two different clients upload files with the same name.

Use an actual temporary file, or a temporary row in a database, before you use `system.util.getGlobals()`. There be dragons. My integration toolkit functions exist specifically to slay those dragons.
