Advanced Customization > Info*Engine User’s Guide > Info*Engine Data Management > Uploading and Downloading BLOBs > Using Form Variables When Uploading BLOBs
  
Using Form Variables When Uploading BLOBs
To upload BLOBs, the HTML form element on your JSP page must include the following attributes:
method="POST"
action="task_to_execute"
enctype="multipart/form-data"
These attributes establish the environment required for streaming the BLOB and storing the form variables.
To understand how to use form variables and how to control BLOB processing, it is helpful to know how the web browser, Info*Engine, adapter, and database interact to transfer BLOB data from the browser to a database. The following interactions identify the major steps that occur when a form is submitted from the browser:
The browser sends the form variables and file data as a stream of data through the web server to the Info*Engine servlet.
To maintain the optimum performance, the Info*Engine servlet and Info*Engine server process the stream as it is received rather than reading and storing the entire stream before doing anything.
The servlet reads any form variables stored at the beginning of the input stream and stores them in the @FORM context group until the first BLOB data is encountered.
When a BLOB is encountered, the Info*Engine servlet stops storing variables and passes the BLOB data on to its output stream so that the stream continues on to the Info*Engine server.
By executing the task that is identified in the HTML form action attribute, the Info*Engine server connects to an adapter and passes the BLOB on to the adapter.
By executing the webject in the task, the adapter then connects to a database and sends the BLOB to the database.
The following example code contains explanatory text and a form for selecting a file to store in the column of a database row. This example posts the data directly to an Info*Engine task using the Info*Engine servlet, meaning the client receives the XML output from task execution upon clicking “Submit”:
<%@page language="java" session="false" errorPage="../IEError.jsp"%>
<%@ taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie" %>
<html>
<head>
<title>Upload File</title>
</head>
<body>
This page prompts for a "name" and "file" to store in an database.
The "name" is used to select a row in the table. The value of
"name" and the "file" contents are stored in columns in the selected row.
The table must be created before this example is run. The table could be created
using a SQL statement like 'CREATE TABLE BLOBTEST (NAME VARCHAR(60),FILECONTENT BLOB)'
<h2>Upload File to Oracle BLOB Column</h2>
<form method="POST" action="/Windchill/servlet/IE/tasks/com/company/UploadBlob.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>File:
    </td>
    <td>
      <INPUT name = "file" type="file" size=50>
    </td>
  </tr>
  <tr> <td align=right>
      <INPUT type=submit NAME="submit" VALUE="Submit" id=button>
    </td>
  </tr>
</TABLE>
</form></body></html>
The file select control displayed through the third form INPUT element provides the vehicle from which the user selects the file to upload and, when the data stream is created, the BLOB data in the file selected is streamed right after the form variables set from the first two INPUT elements.
The UploadBlob.xml task identified in the action attribute of the form element is the task that the Info*Engine server executes. This task (which is described in the next section) uses the form variables to identify the adapter instance and specify the name that corresponds to the BLOB in the table row where the BLOB is stored.
To ensure that Info*Engine stores the form variables for use in the task, the form variables must be set in INPUT elements that are before the INPUT element that selects the BLOB file (as is done the previous example). If the order of the INPUT elements was reversed in the previous example, the form variables required by the task would not be stored in the @FORM context group because they would not appear in the stream until after the BLOB data. Any form variables in the stream after a BLOB are lost because the server does not read the entire stream before transferring it on to the adapter. Instead, the server transfers the BLOB directly to the adapter without first buffering the entire thing in memory. This optimizes performance and allows very large files to be sent to adapters without requiring enormous amounts of system memory.