Advanced Customization > Info*Engine User’s Guide > Info*Engine Data Management > Uploading and Downloading BLOBs > Using Form Variables for Downloading BLOBs
  
Using Form Variables for Downloading BLOBs
The following example code produces explanatory text and a form for selecting a row from a database table containing a BLOB. Clicking “Retrieve” invokes an Info*Engine task that selects the corresponding row from the database table and returns the BLOB it contains:
<%@page language="java" session="false" errorPage="../IEError.jsp"%>

<%@ taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie" %>
<html>
<head><title>Send Blob</title>
</head>
<body>
<P>This page prompts for a "name" of the BLOB file to retrieve from an
database and a "MIME type" to associate with the BLOB file. The
"name" is used to select a row in the table where the BLOB is
stored. The table must be created and BLOBs uploaded to rows in
the table before this example is run. The table could be
created using a SQL statement like 'CREATE TABLE BLOBTEST
(NAME VARCHAR(60),FILECONTENT BLOB)'.

<H2>Download File from BLOB Column</H2>
<P>The MIME type determines which application is opened when the BLOB is
received.  The MIME type is not stored in the table. Enter one of the
following MIME types:
<blockquote>'text/plain'<br>
'application/msword'<br>
'application/msexcel'<br>
'application/vnd.ms-excel'<br>
'image/gif'</blockquote>

<P>Include the single quotes in your MIME Type entry.</p>

<form method="POST" action="/Windchill/servlet/IE/tasks/com/company/DownloadBlob.xml"
enctype="multipart/form-data">
<TABLE>  <tr> <td align=right>
      <B><FONT FACE=arial,helvetica>Adapter Instance:
    </td>
    <td>
      <INPUT name = "instance" type="text" size=50>
    </td>
  </tr>
  <tr> <td align=right>
      <B><FONT FACE=arial,helvetica>Name:
    </td>
    <td>
      <INPUT name = "filename" type="text" size=50>
    </td>
  </tr>
  <tr> <td align=right>
      <B><FONT FACE=arial,helvetica>Mime Type:
    </td>
    <td>
      <INPUT name = "mimetype" type="text" size=50>
    </td>
  </tr>
  <tr> <td align=right>
      <INPUT type=submit NAME="submit" VALUE="Retrieve" id=button>
    </td>
  </tr></TABLE></form></body></html>
The DownloadBlob.xml task identified in the action attribute of the form element is the task that the Info*Engine server executes to download the BLOB. This task (which is described in the next section) uses form variables to identify the adapter instance, specify the name that corresponds to the BLOB in the table row where the BLOB is stored, and set the MIME type.
Example: BLOB Download Task
The following DownloadBlob.xml example task contains one adapter webject. This webject downloads one BLOB to the web browser. The MIME type specified in the MIMETYPE parameter is passed back to the browser and determines which application the browser launches to display the BLOB. The values for the @FORM variables used in the parameters for the webject can be supplied through a form like the form used in the previous section.
The example task assumes that the database table contains the following columns:
The NAME column contains the name of the BLOB.
The FILECONTENT column contains the BLOB data.
<%@page language="java" session="false"%>

<%@ taglib uri="http://www.ptc.com/infoengine/taglib/core"
           prefix="ie" %>

<!--
    Possible MIME Types
      application/msword
      text/plain
      application/msexcel
      application/vnd.ms-excel
--/>

<ie:webject name="Send-Blob-Stream" type="OBJ">
  <ie:param name="INSTANCE" data="$(FORM[]instance[])"
                            default="jdbcAdapter"/>
  <ie:param name="CLASS" data="BLOBTEST"/>
  <ie:param name="ATTRIBUTE" data="FILECONTENT"/>
  <ie:param name="MIMETYPE" data="$(FORM[]mimetype[0])"/>
  <ie:param name="WHERE"
            data="(NAME='$(FORM[]filename[0])')"/>
  <ie:param name="GROUP_OUT" data="STATUS"/>
</ie:webject>