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:


54 comments:

  1. 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

    ReplyDelete
  2. 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

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

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

    Andrejus

    ReplyDelete
  5. 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.

    ReplyDelete
  6. Hi Andrejus,

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

    Regards
    Ashwin

    ReplyDelete
  7. 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

    ReplyDelete
  8. 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

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

    Andrejus

    ReplyDelete
  10. 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

    ReplyDelete
  11. 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

    ReplyDelete
  12. 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

    ReplyDelete
  13. 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.

    ReplyDelete
  14. 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

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

    Andrejus

    ReplyDelete
  16. 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

    ReplyDelete
  17. 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

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

    ReplyDelete
  19. 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.

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

    Andrejus

    ReplyDelete
  21. 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.

    ReplyDelete
  22. 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.

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

    Andrejus

    ReplyDelete
  24. 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.

    ReplyDelete
  25. @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?

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

    Regards,
    Andrejus

    ReplyDelete
  27. 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..

    ReplyDelete
  28. Thanks for update, this is useful.

    Regards,
    Andrejus

    ReplyDelete
  29. Hi Andrejus,

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

    ReplyDelete
  30. You should use JDBC and BLOB type.

    Andrejus

    ReplyDelete
  31. 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.

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

    Regards,
    Andrejus

    ReplyDelete
  33. 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

    ReplyDelete
  34. 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.

    ReplyDelete
  35. You should increase maximum file size limit.

    Andrejus

    ReplyDelete
  36. 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.

    ReplyDelete
  37. Hi Andrejus,

    Thanks for this post.I am trying to customize this behavior. I want two options (User uploading through Browse button as well Drag and drop on the Area)as seen in your workspace. But i want to restrict the maximum files upload to 1. If i change that am not able to drag and drop area, Also I tried to increase the width using ContentStyle property. But, am not able to use the Browse button if I change the UplaodType = Manual.

    Can you please suggest anything.

    I am using 11.1.1.7 JDev verison.

    Thanks,

    ReplyDelete
  38. Hi Andrejus,

    I am using your inputFile example into a Dialog where I have a Cancel button to close this Dialog. The issue is here, when I press the Cancel button I am getting the error: IllegalStateException: popView(): No view has been pushed.

    The cancel method has:
    AdfFacesContext.getCurrentInstance().returnFromDialog(null,null);

    Thanks a million.

    ReplyDelete
  39. I was planning to use 11gR2 for a new project, but looks like it's missing updates from 11gR1.
    What do you suggest to use 11.1.2.4 or or 11.1.1.7 ?

    Thank you

    ReplyDelete
  40. I would suggest 12c, but if it is not possible then 11.1.1.7.

    Andrejus

    ReplyDelete
  41. I have ADF 12c, I used this component, and after few clicks on the page (not on the component) it hangs. The waiting cursor appears, I can't press any button/link. I think there is some JavaScript that never ends. Any idea ?

    ReplyDelete
  42. Sir,
    I use the following code for uploading a file. The code execute without any error but the data does not enter to the DB. the ‘operationbinding’ returns a null value. Can you suggest a solution please…

    public void onFileUpload(ActionEvent actionEvent) {
    DCBindingContainer bc = ADFUtil.getBindingContainer();
    OperationBinding operationbinding = bc.getOperationBinding(“uploadFiletoDB”);
    if(operationbinding!=null){
    operationbinding.getParamsMap().put(“fileName”, fileName);
    operationbinding.getParamsMap().put(“contentType”, contentType);
    operationbinding.getParamsMap().put(“blob”, blob);
    operationbinding.execute();
    }
    System.out.println(“File uploaded successfully”);
    if (inputFile != null) {
    inputFile.resetValue();
    inputFile.setValid(true);
    }
    }

    ReplyDelete
  43. I am facing same issue as Cosmin mentioned above. We have a button on upload page which shows validation errors(if any). it hangs once user clicks on this button. Any idea?

    ReplyDelete
  44. Hi All,

    I am developing an application in ADF JDeveloper 12c, I wanted to know how to save the selected file (through inputfile component)in a folder which is in IDE.

    ReplyDelete
  45. Kindly update link to download project. link expired

    ReplyDelete

  46. You can download all old samples from here - https://code.google.com/archive/p/jdevsamples/downloads

    Andrejus

    ReplyDelete
  47. Hi Andrejus, I faces the same question
    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?

    files.size count wrong

    ReplyDelete
  48. We are not able to handle mandatory check with required="true" .Looks like it is not working. Any suggestions ?

    ReplyDelete
  49. the fragment does not support forms.Therefor how we assign usesuploaded=true

    ReplyDelete
  50. Even in 12c, the af:inputFile leaves "No Files Selected" message in Chrome after files are selected. Easy fix, set inlineStyle="color:transparent;" It goes away. Seems to work in IE too.

    For Ajitha: "the fragment does not support forms." You have to put usesupload=true in the parent jsf page containing the task flow with the jsff.

    ReplyDelete
  51. Hi, I have given maximum size 5
    but when i select more than 2 files it shows its been uploaded, but in value change listener i get 2 files.

    Also when selecting multiple files for upload more than 2MB doesnot get selected to input file.

    ReplyDelete
  52. Hi,

    Im unable to download the same code. Could you provide a working link?
    Im using fmw 12c stack, would the sample work on 12c as well?

    Thanks,
    Sapna

    ReplyDelete
  53. Yes, it should work on 12c.


    You can download all old samples from here - https://code.google.com/archive/p/jdevsamples/downloads

    Andrejus

    ReplyDelete