Uploading files One of the most common tags that retrieves information from the user is the input tag. A standard input can take on several behaviors, which are specified by the type attribute. The default type is text, and it results in a simple text input. Another useful type is the file input, which can be specified via the following HTML: The file input type creates a field through which users can upload files from their local computer or network. The value attribute specifies the name of the initial file, but browsers typically ignore it as a security precaution. The accept attribute gives a comma-separated list of media types accepted, allowing
'); // -->
the browser to filter out inappropriate files. Current browsers generally ignore the accept attribute. (Get more information about file input from the The Web Design Group.) The file input presents a standard method to retrieve the data from the user; however, to actually read the data from the user's machine it gets more involved. To place a file input on the form, you must specify two attributes on the form. You must set the action attribute to POST and the enctype attribute to multipart/form-data on the form tag. Further detail about the format of mulitpart/form-data is available in RFC 1867 on the Internet Engineering Task Force Web site. The enctype attribute specifies the content type used in submitting the form, it and defaults to application/x-www-form-urlencoded. This content type results in name/value pairs sent to the server as The following example allows a user to upload a file to a servlet: Storing files The first reason was simplicity. Using the IFS requires the production of a naming scheme to associate files with a particular claim. That approach can become somewhat complex and problematic in that it requires you to manage the link, mostly likely contained in each database record, between your code and the directory structure where those files reside. If at some point the directory structure changes or is reorganized, or the data is moved completely, the links to those files must be changed for all the old records in order to reflect the new location and organization. With DB2 BLOB support, we simply store the files in a traditional record, along with its associated "meta data." Referencing and maintaining the link between your attachments and your database record becomes a non-issue. We needed to record "meta data," such as upload time, upload user and claim number, with each file. Using the DB2 approach, we were able to simply attach extra fields to our file and easily record this additional meta data. Using the IFS would have required an associated DB2 record to hold the meta data. The second reason for choosing the DB2 database was adequate performance. We were concerned that the DB2 BLOB support would not perform well because of the need to read the BLOB out of the database for each viewing request. To minimize the risk, we put together a prototype application and verified that performance was adequate given our needs. We did not do any performance comparisons, but our thought was that the IFS may have an advantage because the Web server or browser could cache the files at their respective levels. DB2 files with BLOB fields For this application, the field named FILE_BLOB was set to allow a file size of up to 10 MB. The size of this field would obviously be an area of consideration at design time, depending on the application being created and what was going to be stored in the BLOB. The default size for a BLOB field in DB2, if not explicitly specified as above, is 1 MB. The maximum size for a BLOB field in DB2 is 2 GB. We felt that, in most cases, pictures, documents, spreadsheets, and the like would typically be accommodated by 10 MB. The larger the allowable upload, the more space your file will potentially occupy. Writing the BLOB to DB2 Say, for instance, that we have an HTML text input field defined in the following manner: The associated Java code that would get this value from the request would be This scenario is changed with the multipart/form-data encoding. The process of gathering the binary data out of the request object, parsing the information and placing it an accessible form is involved and is beyond the scope of this article. A best practice that we recommend would be to wrapper the Request Object with a special object that would handle the parsing of the multi-part form data and place the data from the form in the attributes object of the request. (We recommend doing a Google search on "multi part encoding parsing Java" or similar keywords to obtain direction and insight into this process.) The following example assumes that such a wrapper class exists and we are able to retrieve the data from the request attributes. Querying the BLOB fields A BLOB field is read a little differently from traditional database types because of its possible large size. BLOB fields are read using the simple JDBC result set APIs. Once you have read the BLOB field, it is sent to the browser by obtaining the HTTPServletResponse and getting the outputStream. You're ready for BLOBs ---------------------------
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iSeries Security - Security Tools, Physical Security and System Security |
| About Us | Contact Us | For Advertisers | For Business Partners | Site Index | RSS |
|
|
|
|||||||