# How to query video from SQL Server into Perspective VideoPlayer component?

**URL:** <https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 19, 2022, 8:09pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807 "2022-05-19T20:09:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericmoulton](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@ericmoulton](https://forum.inductiveautomation.com/u/ericmoulton)\
**Post date:** [May 19, 2022, 8:09pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807/1 "2022-05-19T20:09:32Z")

</div>

I am storing images in a SQL Server as varbinary(max), and retrieving them into the source property of an image component with a scalar named query like:  
_select cast(’’ as xml).value(‘xs:base64Binary(sql:column("[tbl].[ImageCol]"))’, ‘varchar(max)’)_  
and the script transform:  
_“data:imagef;base64,%s”%value_

That works great.  
How can I do this with videos though? I don’t have a specific format\codec in mind - I’m flexible if there’s a solution.

Thanks for your help!  
Eric

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [May 19, 2022, 8:29pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807/2 "2022-05-19T20:29:27Z")

</div>

@pturmel would your blob module be of use here?

---

<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:** [May 19, 2022, 8:36pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807/3 "2022-05-19T20:36:48Z")

</div>

Probably, if the video isn’t too large. Worth a try.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [May 19, 2022, 8:51pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807/4 "2022-05-19T20:51:18Z")

</div>

> [@Automation Professionals' Blob Server Module](https://forum.inductiveautomation.com/t/automation-professionals-blob-server-module/57970):
>
> Automation Professionals is pleased to announce an alpha release of its new Blob Server Module. Available only for Ignition v8.1, here. The Blob Server Module provides a simple way to deliver images, PDF files, or other binary content from a database to your Perspective clients or other web applications. Without needing the WebDev module. All you need is a Named Query that has appropriate security settings and returns a single row with two columns: Content, and ContentType. Modest documentati…

---

<div class="post-metadata">

**Author:** ![ericmoulton](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@ericmoulton](https://forum.inductiveautomation.com/u/ericmoulton)\
**Post date:** [May 20, 2022, 3:57pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807/5 "2022-05-20T15:57:52Z")

</div>

It works and it works great! Thanks!

In looking for some guidance from Google this morning, the overwhelming advice from the db community is to never, ever store media like this in a db, but to use a filesystem instead.

So… that’s that I guess.

Thanks for your help though 🙂

---

<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:** [May 20, 2022, 4:09pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807/6 "2022-05-20T16:09:24Z")

</div>

> [@ericmoulton](#):
>
> never, ever store media like this in a db

This is why I said if "isn't too large". Media players accessing URLs will typically request specific byte ranges to avoid a monster transfer in one gulp. That gets converted into the appropriate filesystem offsets for efficiency.

Some DBs provide similar fractional BLOB transfer, but it isn't part of JDBC and Ignition can't expose it. So running the named query will grab the whole content, even if the client requested just a chunk. There's a couple trade-offs that apply:

- Allow caching of the named query. It'll run just once and the blob held in memory. Allows the client to request chunks without hammering the DB. But Gateway memory usage will skyrocket.

- Don't cache the named query. Your DB will be hammered, but memory will be returned quickly.

So, stick to small files. Or switch to WebDev.

---

<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:** [May 20, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/how-to-query-video-from-sql-server-into-perspective-videoplayer-component/59807/7 "2022-05-20T16:14:12Z")

</div>

I just realized that there’s another option: segment your video into small chunks and stick those into your DB. The tools for that will produce a playlist file that you supply to clients from the main URL. Modify that file’s content to point at the individual chunks. Then you can use a short cache duration with that named query.
