Friday, April 12, 2013

Multiple Files Upload - Unlimited Files Upload in ADF 11g PS6

Among other new components and features available in ADF 11g PS6 - there is one very important. File Upload ADF Faces component was upgraded to support multiple or basically infinite file upload. This is good to see how ADF framework is progressing with each new release, this is another argument why you should use ADF.

I was using sample application - MultipleFileUpload.zip, to test how multiple file upload works. You drag and drop regular ADF Faces input file component:


There is option to set number of rows (number of files in other words) to be rendered by input file component (this number can be changed dynamically on runtime):


Another property that must be set - MaximumFiles. With this property you can specify maximum number of files to be uploaded at once (also can be changed dynamically on runtime):


This is about UI part. Now how to handle multiple files and how to get Input Stream. You can create Action Listener for Upload button and handle multiple files input from such listener:


Important part - if you plan to allow multiple files upload, you should bind ADF Faces input file component the List. In such way, we have access to collection of files user is uploading:


Lastly don't forget to set UsesUpload=true property as usual for the container JSF page on af:form tag:


Set UsesUpload=true property for af:form:


Here how it looks on ADF UI - multiple files are submitted to be uploaded (even file upload progress bar is rendered while file is being loaded):


Status on the server informs about successful multiple files upload:


38 comments:

Anonymous said...

Where are we setting to which server we are uploading the file?
Do we need to set up the host name of server and user name and password of the user who has the permission to set to some specific location?
Please reply ASAP

Andrejus Baranovskis said...

You are not uploading to the server. You are getting stream in ADF Managed Bean on the server and can save it wherever you prefer.

Andrejus

Anonymous said...

Hi,
Information is useful.But on click of SaveFiles , page is getting refreshed with no uploaded file is being displayed .

Andrejus Baranovskis said...

This is just sample app, it doesnt store files on the server, but demo file upload component.

Andrejus

ಆಶ್ವಿನ್ ಆಲ್ಮೆಡ (Ashwin Almeida) said...

Hi Andrejus,

I tried you application it works fine, I have couple of questions.

In the example if suppose 3 files are uploaded, I used manual mode. After the file is uploaded where is it temporarily stored. (any location or in memory ). As I see we read the inputstream of files only in SaveFile Method on click of button

If its stored in memory , wont that eat on the heap size.

In our application we were using a 3rd party app, now that ADF has the component, we want to use this feature. Our applicaion has to support large file average 10MB/file. Hence have concerns as to how does the ADF input file deal with the inputstreams.

ಆಶ್ವಿನ್ ಆಲ್ಮೆಡ (Ashwin Almeida) said...

Hi Andrejus,

Would you be able to provide the insight on the question which I had posted.

Regards
Ashwin

Andrejus Baranovskis said...

It stores it in the memory by default, you can configure maximum file upload size. Also you can configure temp directory to minimize memory usage. ADF file upload is based on trinidad, here you can read more info how to configure it: http://myfaces.apache.org/trinidad/devguide/fileUpload.html

Andrejus

ಆಶ್ವಿನ್ ಆಲ್ಮೆಡ (Ashwin Almeida) said...

Thanks Andrejus for the reply,

Just to summaries my understanding
1) org.apache.myfaces.trinidad.UPLOAD_MAX_MEMORY specifies what is the max memory heap to be used per request, if more bytes than this is received then the bytes are stored on the disk (temp) location.

2) org.apache.myfaces.trinidad.UPLOAD_MAX_DISK_SPACE is maximum file size that can be uploaded per request.

So, In cases where a application used file upload a lot ( multiple users uploading at the same time) , we better have smaller values to the org.apache.myfaces.trinidad.UPLOAD_MAX_MEMORY so that the heap doesn't fill up.

Regards
Ashwin

Andrejus Baranovskis said...

Yes, i think so. But please give a test and see how it works in your environment.

Andrejus

Anonymous said...

Is there any way to view uploaded documents in ADF ? For eg : User can able to upload any type of file (image,pdf,doc,.cvs,.avi..etc..) all the files contents will be stored in DB as BLOB object, My question is is there any simple way that user can render the same file how they have uploaded ?

Thanks
Ravi

Andrejus Baranovskis said...

Yes, through the servlet.

Andrejus

Maroof Ahmad said...

Hi Andrejus,
Thanks for this post. I am creating same utility in Jdeve 12c for unlimited files so i am chosen maxFileSize=-1, but here i am facing files.size() counting wrong no of files.
Ex . I am selecting 10 files in browser but its printing files.size()=19 or sometimes different-different.
What i need to change in settings?
Or its bug in 12c. Please check a dummy code.

Thanks and Regards
Maroof Ahmad

Maroof Ahmad said...

Hi Andrejus,

I am uploading my files in blob, but when i am choosing more than 10 files
then i am getting below error,

javax.faces.application.ViewExpiredException: viewId:/folderUpload.jspx - ADF_FACES-30107:The view state of the page has expired. Reload the page

for more detail take a look

https://forums.oracle.com/thread/2590127

Maroof

Vijay Eadala said...

Hi, is there a way you can stop or cancel the streaming from the browser? I want to give the user ability to cancel the file they are uploading for various reasons.

Dev ADF said...

I am working with ADF PS4.
ADF_MAIN.OTN4_GENERIC_080429.0116.4949

I want to upload multiple files but i don't find maximumFiles attribute. how can i do ?
thanks

Andrejus Baranovskis said...

Your JDEV is too old. Check this post title, it says - PS6 :-)

Andrejus

Dev ADF said...

Yes I confirm that the JDEV is too old but i want to know if there is a way to upload multiple files with this version. I succeeds to upload single file. Have any suggestion, other ways to do it ?
thanks a lot

Andrejus Baranovskis said...

Yes, you can implement custom task flow. Actually I was planning to post similar blog post, I will put it on my todo list.

Andreju

Dev ADF said...

thanks, please tell me when it is done. I am waiting for trying :)

Anonymous said...

hi Andrejus

Thanks for the post. I am using 11.1.2.4 (yes this is R2) but this is newer than 11.1.1.6 (R1)

in 11.1.2.4 I get 2 errors that attributes are not recognized for
maximumFiles and autoHeightRows attributes.
What do I need to do in order for this to work in 11.1.2.4? Thanks.

Andrejus Baranovskis said...

Newer doesnt mean better :) 11.1.2.4 doesnt have multiple files upload feature.

Andrejus

Xuan-Tu Tran said...

Hi Andrejus,

Thank you for your post. It's really useful for me. Keeping your work.

By the way, I am wondering how can I customize my input file UI. I mean, I want to resize the content box that contain some info (file name, size, status and delete button). Because it look like to small.

I am looking forward from your respond.

Mayur said...

Hi andrejus,

For me multiple file upload works with the settings you proviede. Only thing is on click on submit button, browser shows confirmation pop up to leave page. Any idea on how can i get rid of this browser pop up.

Andrejus Baranovskis said...

This doesnt sound related to file upload. May be you have set UncommitedDataWarning option on af:document tag.

Andrejus

Mayur said...

Andrejus, Thanks for quick response.
I did check, UncommitedDataWarning option, for af:document in my jspx file and it is set to off.
One more thing, if i set maximum file property to 1 and make appropriate changes in my bean, it browser do not ask that confirmation.

Anonymous said...

@Mayur,
I'm also facing uncommitted data warning. How can i resolve the issue?
If i upload more than 2 files, i'm getting this issue..
Is it ADF bug?

Andrejus Baranovskis said...

I was not able to reproduce it with my sample. Which JDEV version you are using?

Regards,
Andrejus

Anonymous said...

Regarding 'uncommitted data warning'...I resolved it...
Earlier, we set the client state max tokens to 3 for performance improvement. That was causing the issue.

org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS
3

I increased the value. It worked..

Andrejus Baranovskis said...

Thanks for update, this is useful.

Regards,
Andrejus

Anonymous said...

Hi Andrejus,

How to load these files to oracle database in adf .Could you please help

Andrejus Baranovskis said...

You should use JDBC and BLOB type.

Andrejus

Anonymous said...

After you select multiple files, how come it still shows "No file chosen" next to the Choose Files button? I believe the "No file chosen" text comes from the Chrome browser (in Firefox, the text shown is "No files selected" next to a Browse button).

It seems like an adf bug that "No file chosen" is still visible after selecting files. If I just try using an input type=file tag with multiple="true" in standard html, after selecting 2 files, it will show "2 files" next to a Choose Files button (in Firefox, it will show "2 files selected" next to a Browse button). But somehow the adf inputFile component does not behave similarly.

Andrejus Baranovskis said...

But this works with my sample app as per screenshot. May be you are missing some steps?

Regards,
Andrejus

Anonymous said...

Not sure if you understood my question about the "No file chosen" issue. Even in the screenshot above (2nd to last one, http://1.bp.blogspot.com/-pakU4ZISswU/UWg0Q0-07xI/AAAAAAAAJSg/HhnM8SivcYc/s1600/8.png), it shows "No file chosen" next to the Choose Files button after you already selected the 3 files.

Andrejus Baranovskis said...

This is not a bug, just file upload component says - no file chosen to upload. Previously uploaded files are already uploaded. I agree, it could be misleading.

Andrejus

Suneetha Mariswamy said...

I am having an application which uploads multiple files. I selected a huge file for upload. It shows Stop Uploading button along with progress bar. But it still shows "No Files Selected". So looks like ADF bug.

Andrejus Baranovskis said...

You should increase maximum file size limit.

Andrejus

Kameswari Srishtu said...

Hi Andrejus,

Could you please provide me a input on how to resize the content box which is holding FileName, Size and Delete button.. that would be great.

I am using Jdev 11.1.7.

thanks.