# Inserting Image in database using Upload component in perspective

**URL:** <https://forum.inductiveautomation.com/t/inserting-image-in-database-using-upload-component-in-perspective/93593>\
**Category:** Ignition\
**Tags:** database, ignition81, perspective, scripting\
**Created:** [July 23, 2024, 9:12am UTC](https://forum.inductiveautomation.com/t/inserting-image-in-database-using-upload-component-in-perspective/93593 "2024-07-23T09:12:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Purushothaman\_R](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Purushothaman\_R](https://forum.inductiveautomation.com/u/Purushothaman_R)\
**Post date:** [July 23, 2024, 9:12am UTC](https://forum.inductiveautomation.com/t/inserting-image-in-database-using-upload-component-in-perspective/93593/1 "2024-07-23T09:12:55Z")

</div>

Hi, I am trying to upload an image which is in my local computer to ignition database how can i do that. I have a upload component in my view and I have configured events onFileReceived scripting. The script is

> Blockquote# This script is triggered when a file is uploaded  
> def onFileReceived(self, event, file):  
> # Get the bytes of the file  
> image\_data = event.file.getBytes()

```
# Get a database connection
db = system.db.getConnection("MySQLlite")

# Create a SQL query to insert the image data into the database
query = "INSERT INTO image_store (image_name, image_data) VALUES (?, ?)"

# Execute the query
system.db.runPrepUpdate(query, [event.file.name, image_data], db)

# Close the database connection
db.close()

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/c/3c6658ad057e075ce7a0dee3dc29bb29df105fd2.png)

Anyone kindly help me

---

<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:** [July 23, 2024, 11:23am UTC](https://forum.inductiveautomation.com/t/inserting-image-in-database-using-upload-component-in-perspective/93593/2 "2024-07-23T11:23:54Z")

</div>

Please use the forum's "preformatted text" button for your script, not blockquote, so we can see everything (including indentation) properly.

Please also share any logged errors (also preformatted) that happen in the gateway logs when you attempt an upload.

---

<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:** [July 23, 2024, 3:08pm UTC](https://forum.inductiveautomation.com/t/inserting-image-in-database-using-upload-component-in-perspective/93593/3 "2024-07-23T15:08:53Z")

</div>

> [@Purushothaman\_R](#):
>
> ```python
> # Get a database connection
> db = system.db.getConnection("MySQLlite")
> 
> ```

Ignition has no such system function.

Don't trust ChatGPT or any other LLM for Ignition specific scripting advice. It will happily and confidently give you completely false information.

---

<div class="post-metadata">

**Author:** ![Purushothaman\_R](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Purushothaman\_R](https://forum.inductiveautomation.com/u/Purushothaman_R)\
**Post date:** [July 24, 2024, 10:12am UTC](https://forum.inductiveautomation.com/t/inserting-image-in-database-using-upload-component-in-perspective/93593/4 "2024-07-24T10:12:13Z")

</div>

Ok @paul-griffith I will try to maximum get idea from Ignition Forum answers or my Senior's advice

---

<div class="post-metadata">

**Author:** ![Purushothaman\_R](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Purushothaman\_R](https://forum.inductiveautomation.com/u/Purushothaman_R)\
**Post date:** [July 24, 2024, 10:13am UTC](https://forum.inductiveautomation.com/t/inserting-image-in-database-using-upload-component-in-perspective/93593/5 "2024-07-24T10:13:51Z")

</div>

ok @pturmel I will use preformatted text hereafter
