# File retrieval from database using WebDev Module

**URL:** <https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 4, 2024, 10:11am UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522 "2024-09-04T10:11:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Rahul\_J](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Samuel\_Rahul\_J](https://forum.inductiveautomation.com/u/Samuel_Rahul_J)\
**Post date:** [September 4, 2024, 10:11am UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/1 "2024-09-04T10:11:21Z")

</div>

```python
def handleFileUpload(event):
    # Extract file details from the file upload component's custom properties
    fileName = event.file.name
    fileSize = event.file.size
    fileBytes = event.file.getBytes()

    # Set custom properties
    self.custom.fileName = fileName
    self.custom.fileSize = fileSize
    self.custom.fileBytes = fileBytes

    # Create a dictionary with the parameters
    params = {
        "fileName": fileName,
        "fileSize": fileSize,
        "fileBytes": fileBytes # Adjust if necessary based on your SQL column type
    }

    # Execute the named query to insert the file data
    system.db.runNamedQuery("File Storage/file_storage_query", params)

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 4, 2024, 10:26am UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/2 "2024-09-04T10:26:08Z")

</div>

Welcome to the forum, Samuel. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). You can then edit your question to format correctly and the indentation will show correctly.

---

<div class="post-metadata">

**Author:** ![flexware](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/flexware/32/66243_2.png) [@flexware](https://forum.inductiveautomation.com/u/flexware)\
**Post date:** [September 4, 2024, 2:53pm UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/3 "2024-09-04T14:53:06Z")

</div>

Check out pturmel's [Blob Serve](https://forum.inductiveautomation.com/t/automation-professionals-blob-server-module/57970) module - we've used it in production to serve up PDF files stored as blobs in a database and it works flawlessly! This will avoid the additional cost of the WebDev module, if you don't need it for any other reason.

---

<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:** [September 4, 2024, 3:04pm UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/4 "2024-09-04T15:04:58Z")

</div>

I feel like I'm going to have to bookmark a post that says this so I can keep linking to it, but:  
It looks like you're using an LLM (ChatGPT, etc) to help with Ignition coding. Don't do that. They simply don't have the requisite domain "knowledge" to avoid blind alleys. For instance:

```python
    # Set custom properties
    self.custom.fileName = fileName
    self.custom.fileSize = fileSize
    self.custom.fileBytes = fileBytes

```

This is doing _nothing_. It is, in fact, **actively bad** , because it's taking up a huge chunk of gateway and session memory, and burning a ton of CPU cycles, to store a lossy representation of the binary data that you're immediately storing into the database anyways.

You didn't actually ask a question, besides your title, so, if you _already have the WebDev module_, try looking around on the forums for example code that can help. I can guarantee you it exists. If you've tried to find something and can't get it working, post your code that's not working _and what's not working_.  
If you _don't_ already have the WebDev module, then I'll echo the recommendation of Phil's _free_ module.

---

<div class="post-metadata">

**Author:** ![Samuel\_Rahul\_J](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Samuel\_Rahul\_J](https://forum.inductiveautomation.com/u/Samuel_Rahul_J)\
**Post date:** [September 5, 2024, 4:57am UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/5 "2024-09-05T04:57:02Z")

</div>

I have saved the files in the DB using the query:

```
# Extract file details from the file upload component's custom properties
fileName = event.file.name
fileSize = event.file.size
fileBytes = event.file.getBytes()

# Create a dictionary with the parameters
params = {
    "fileName": fileName,
    "fileSize": fileSize,
    "fileBytes": fileBytes # Adjust if necessary based on your SQL column type
}

# Execute the named query to insert the file data
system.db.runNamedQuery("File Upload/file_storage_query", params)

```

I want to retrieve the file using Web Dev module and display the file onto the PDF viewer component. It will be of great help, if I can get to know how to do this.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 5, 2024, 7:51am UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/6 "2024-09-05T07:51:59Z")

</div>

Web dev is used to expose an API to the "outside world", which doesn't look like what you're after. There's no reason to use webdev if you want to display things with ignition components.

Tell us more about your use case.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 5, 2024, 11:13am UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/7 "2024-09-05T11:13:51Z")

</div>

Except with the PDF viewer in Perspective... you need to use the WebDev module or @pturmel blob server: [Automation Professionals' Blob Server Module](https://forum.inductiveautomation.com/t/automation-professionals-blob-server-module/57970)

But as @pascal.fragnoud noted, tell us more about what you need to do. It'll help us help 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:** [September 5, 2024, 2:24pm UTC](https://forum.inductiveautomation.com/t/file-retrieval-from-database-using-webdev-module/95522/8 "2024-09-05T14:24:33Z")

</div>

Samuel, you posted this as an additional top level topic instead of replying to your existing threads. I've merged the threads together, but don't do this in the future.
