File uploading using JPDK Portlet API on Oracle Portal Server

It has always been a topic of discussion about file uploading in portlet specially with JPDK portlet on Oracle Portal server.

I also faced some technical challenges while working with this but now come up with a solution and wants to share here.You will find numerous post on OTN (Oracle Technology Network) regarding File upload in Portlet in JPDK Portlet API.So finally I though about why not to write an article on my blog for the same.So here we go.......

1. Create a portlet application from your JDeveloper and just write a new servlet into any of your package. This servlet will be doing the actual file uploading functionality.

2. Make a entry for this servlet in your web.xml.

3. Let us say you have two JSP's, one is MyProfile.jsp and other is FileUpload.jsp. The FileUpload.jsp will be opened in a pop up window (<pass required parameters> ) when you click on a link from MyProfile.jsp.(Note:- of course you might be having other Business logic and DB related classes and some other JSP also)

4. In the pop up window OR FileUpload.jsp, use the following as your form tag entry <form method="post" action="<%=request.getContextPath()%>/FileUploadServlet" name="fileuploadform" enctype="multipart/form-data">

5. Once done till step 4, deploy your portlet application from the JDeveloper. You can use application server connection from within your JDeveloper for deployment of your Portlet Application.

Let us understand complete scenario in a more practical way.
Let us say you are creating a Matrimonial Portlet app, where user will be entering his profile detail and will also upload his photograph.Matrimonial Portlet must be having these minimum files as follows:
Two Java files and and Two JSP files UserProfile.jsp and FileUpload.jsp.Again, some other files also present your Business related operations.

Now the Functional approach will be like this

1. From, the UserProfile.jsp will be rendered. In this jsp user will enter his profile detail and at the end he will upload his photograph.

2. It means some where On some link )on this UserProfile.jsp, you will call<pass required parameters>) which will result in opening FileUpload.jsp in a pop up window and this is the jsp where user will upload his photograph.

3. Once the photograph is uploaded, pop up window will be closed and user will come back to UserProfile.jsp and finally press the submit button for submitting his complete profile detail.

The important points in this article is to look into is
As JPDK portlet API doesn't provide any mechanism for file uploading in portlet, so i thought of introducing servlet to uploade file on server and a popup window for browsing file from file system.
Browsing a file from within a popup window is distinguishing the file uploading functionality from portlet technology.
Here file uploading component has nothing to do with portlet technology and it's just a servlet stuff.And since it is separate component, you can just plug in this with any of your portlet app where ever file uploadingis required.
I hope, this article will help to understand File Uploading in JPDK portlet for Oracle Portal Server.You can have a look on the thread for File Upload function in Portlet on OTN for the same.

Feel free to post your comment if you have any queries.


mathlouthi said...

Very important! i used the same idea but with an iframe in the form (Portlet JSR168)!

Thank you

nazarmohd said...

Thank you very much for this helpful information. I used the above mentioned steps to upload files to a folder. However, im facing a problem. How to give a link to download those uploaded files? i have tried all the basic steps like file:///d:/abc.doc request.getContextPath/abc.doc"> and also javazoom's download4j class files. The problem is that its accepting the path if the file is kept in the folder before compiling the application. If after compiling, i move a file there its unable to access the file. Can u please help me out in this?