# Unable to upload files

**URL:** <https://forum.inductiveautomation.com/t/unable-to-upload-files/94223>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [August 6, 2024, 1:31pm UTC](https://forum.inductiveautomation.com/t/unable-to-upload-files/94223 "2024-08-06T13:31:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad\_Gregory](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chad_gregory/32/51192_2.png) [@Chad\_Gregory](https://forum.inductiveautomation.com/u/Chad_Gregory)\
**Post date:** [August 6, 2024, 1:31pm UTC](https://forum.inductiveautomation.com/t/unable-to-upload-files/94223/1 "2024-08-06T13:31:34Z")

</div>

I am trying to upload files in Ignition Perspective but when calling `event.file.getBytes()` I am getting an array which is causing the insertion into the database to fail as it is expecting varbinary(MAX). I am working with the example provided in the docs.

```python
def runAction(self, event):
	from traceback import format_exc
	
	log = system.util.getLogger("Photo Upload")
	
	try:
		filename = event.file.name
		filedata = event.file.getBytes()
		
        # Output: <type 'array.array'>
		log.info(str(type(filedata)))
	
	except Exception:
		log.error(format_exc())
	
	# Use a query to insert the file
#	query = "INSERT INTO photos (filename, photodata) VALUES(?, CONVERT(varbinary(MAX), ?))"
#	args = [filename, filedata]
#	db = self.session.custom.dbConnection
#	system.db.runPrepUpdate(query, args, db)

```

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

Side note: I think storing files in the database is disgusting so if anyone has tips on where I should store the files using `system.file.writeFile()`

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/530b43eff88471717801b256cd44e3a0c8da6b0a.jpeg)

---

<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:** [August 6, 2024, 1:59pm UTC](https://forum.inductiveautomation.com/t/unable-to-upload-files/94223/2 "2024-08-06T13:59:27Z")

</div>

Yes, `bytes()` is an array. Of bytes. 🤷‍♂️

Show your complete script with SQL.

Most JDBC drivers are perfectly happy to send java byte arrays to databases using "Prep" queries (`?` substitutions) or named queries (value parameters).

> [@Chad\_Gregory](#):
>
> I think storing files in the database is disgusting

Try putting millions of small files in a folder in a filesystem, and compare to putting small blobs in a production-grade database. You'll change your mind, I suspect.

If you want to use files, and sometimes you should, you probably want to use the WebDev module to serve them to clients on demand.
