Web Applications that Upload Files

One thing that many web applications do is let users upload files from their own computers. For instance, I have a system where application forms are tracked through a process leading to the approval or disapproval of the application. My users can upload supporting documents for the application, which are usually PDF files created from FAX or scanned paper documents.

In Hypertext Transfer Protocol (HTTP), POST messages let you attach a file, much in the same way that you can attach files to e-mail messages, with Multipart Internet Mail Extensions (MIME). This is still mostly used to attach data from an HTML form, and that means that you are attaching only one file. However, a later extension to HTML allows you to specify in the FORM tag that the form will be posting multi part attachments, which allows the client to upload files along with the data from the form. To do this, a new INPUT field type was added to the HTML elements, FILE, which appears on the browser screen as a text field, but usually with a browse button next to it. The user can fill in the name of a file accessible on her/his local computer or press the browse button to be sent to the normal file open dialog for his/her operating system. When the form is submitted, the chosen file is uploaded as an attachment, along with the form data, including the data field with the file name â€“ more about this later. In ADF Faces, we use an inputFile component to upload files, but it is still rendered in HTML as an <input type="file" /> tag.

On the web server side, there have to be mechanisms for handling both GET and POST messages and sending back the proper file in response. JEE application servers are no different. When you put an inputFile component in an ADF Faces page, the value attribute references an UploadedFile object that will normally be defined in a backing bean. When the form is submitted, behind the scenes, there is an UploadedFileProcessor on the application server which will normally upload the file to a temporary storage area and associate it with the UploadedFile. You could substitute your own code for this and do it another way, but why make more work for yourself if you don't absolutely have to? The UploadedFile object has methods for getting the file name, size and, of course, the data in the file as an InputStream. Notice that the upload actually occurs as part of the HTTP request; it is NOT a separate action. So, by the time a method in your backing bean is called to process the file, the file has ALREADY been uploaded to the application server.

This has some implications that are useful to keep in mind. For one thing, since the file has already been uploaded, your backing bean cannot use an attribute of the file, like its size, to determine whether to upload the file - it is too late in the process. All it can do is decide whether to save the file somewhere - the database or the application server's file system, or let it be discarded in normal clean up. However, you can control the UploadedFileProcessor that stores the file in temporary storage with the following file upload context parameters in web.xml. This is from the ADF Developers Guide:

oracle.adf.view.faces.UPLOAD_TEMP_DIR--Specifies the directory where temporary files are to be stored during file uploading. Default is the user's temporary directory.

oracle.adf.view.faces.UPLOAD_MAX_DISK_SPACE--Specifies the maximum amount of disk space that can be used in a single request to store uploaded files. Default is 2000K.

oracle.adf.view.faces.UPLOAD_MAX_MEMORY--Specifies the maximum amount of memory that can be used in a single request to store uploaded files. Default is 100K.

Disclaimer: Blog contents express the viewpoints of their independent authors and
are not reviewed for correctness or accuracy by
Toolbox for IT. Any opinions, comments, solutions or other commentary
expressed by blog authors are not endorsed or recommended by
Toolbox for IT
or any vendor. If you feel a blog entry is inappropriate,
click here to notify
Toolbox for IT.

This is my favorite Oracle conference. It is completely devoted to people who make their livings developing applications with Oracle tools and Oracle databases, not just the original Oracle RDBMS, but also Essbase, Hyperion, My SQL, RDB, TimesTen etc. Very technical, little hype.

This year I'm the content chair for the ADF and MAF track. We're putting together a terrific lineup of speakers, so I hope you can join us. I'm doing the Thursday deep dive on ADF Security with Peter Koletzke.

My second favorite conference. Oracle Develop is now an official Oracle OpenWorld Stream, but still features the same great content. Because this is Oracle's show, they send their best presenters, like Frank Nimphius, Lynn Munsinger, and Shay Shmeltzer.

I haven't been to Collaborate for a few years, because the best content in the IOUG part of the conference is very DBA-oriented, and I've surrendered my DBA hat. But if you are primarily a DBA or database developer, Collaborate is well worth your time.

Copyright 1998-2015 Ziff Davis, LLC (Toolbox.com). All rights reserved. All product names are trademarks of their respective companies. Toolbox.com is not
affiliated with or endorsed by any company listed at this site.