Handling BLOBs

From Wiki

Jump to: navigation, search

In the data model you can define BLOB attributes. This attributes are objectified using an instance of a particular object implementing the RTXBLOBData interface. This type of object permits to access some properties of the wrapped BLOB:

  • name: the file name
  • length: the file size in bytes
  • extension: the file extension

You can use the following data unit template to see BLOB information.

[% def file = unit.selectSingleNode("layout:Attribute[@name='file']") %]

upload path: ${<wr:UnitId/>.data.[%= getFieldName(file)%]}
name: ${<wr:UnitId/>.data.[%= getFieldName(file)%].name}
length: ${<wr:UnitId/>.data.[%= getFieldName(file)%].length}
extension: ${<wr:UnitId/>.data.[%= getFieldName(file)%].extension}    

In the Web page you will see something like

upload path: /upload/ent1/1/test.pdf
name: test.pdf
length: 2000
extension: pdf

The following code according to the Storage Type

${<wr:UnitId/>.data.[%= getFieldName(file)%]}

represents

  • the path of the file stored on the file system under the Web application "upload" folder, if the BLOB attribute is stored on the file system
  • a query string describing how to retrieve the BLOB binary data, if the BLOB attribute is stored on the database

A working example

For example if you want to render an image into the HTML page you can use one of the following templates depending on the chosen Storage Type

  • BLOB stored on file system
<a href="${<wr:UnitId/>.data.[%= getFieldName(file)%]}">
  <c:out value="${<wr:UnitId/>.data.[%= getFieldName(file)%].name}"/>
</a>
  • BLOB stored on the database
<a href="<webratio:BLOB value="${<wr:UnitId/>.data.[%= getFieldName(file)%]}"/>">
  <c:out value="${<wr:UnitId/>.data.[%= getFieldName(file)%].name}"/>
</a>
Personal tools