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:
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
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:
Where are we setting to which server we are uploading the file?
ReplyDeleteDo 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
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.
ReplyDeleteAndrejus
Hi,
ReplyDeleteInformation is useful.But on click of SaveFiles , page is getting refreshed with no uploaded file is being displayed .
This is just sample app, it doesnt store files on the server, but demo file upload component.
ReplyDeleteAndrejus
Hi Andrejus,
ReplyDeleteI 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.
Hi Andrejus,
ReplyDeleteWould you be able to provide the insight on the question which I had posted.
Regards
Ashwin
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
ReplyDeleteAndrejus
Thanks Andrejus for the reply,
ReplyDeleteJust 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
Yes, i think so. But please give a test and see how it works in your environment.
ReplyDeleteAndrejus
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 ?
ReplyDeleteThanks
Ravi
Yes, through the servlet.
ReplyDeleteAndrejus
Hi Andrejus,
ReplyDeleteThanks 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
Hi Andrejus,
ReplyDeleteI 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
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.
ReplyDeleteI am working with ADF PS4.
ReplyDeleteADF_MAIN.OTN4_GENERIC_080429.0116.4949
I want to upload multiple files but i don't find maximumFiles attribute. how can i do ?
thanks
Your JDEV is too old. Check this post title, it says - PS6 :-)
ReplyDeleteAndrejus
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 ?
ReplyDeletethanks a lot
Yes, you can implement custom task flow. Actually I was planning to post similar blog post, I will put it on my todo list.
ReplyDeleteAndreju
thanks, please tell me when it is done. I am waiting for trying :)
ReplyDeletehi Andrejus
ReplyDeleteThanks 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.
Newer doesnt mean better :) 11.1.2.4 doesnt have multiple files upload feature.
ReplyDeleteAndrejus
Hi Andrejus,
ReplyDeleteThank 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.
Hi andrejus,
ReplyDeleteFor 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.
This doesnt sound related to file upload. May be you have set UncommitedDataWarning option on af:document tag.
ReplyDeleteAndrejus
Andrejus, Thanks for quick response.
ReplyDeleteI 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.
@Mayur,
ReplyDeleteI'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?
I was not able to reproduce it with my sample. Which JDEV version you are using?
ReplyDeleteRegards,
Andrejus
Regarding 'uncommitted data warning'...I resolved it...
ReplyDeleteEarlier, 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..
Thanks for update, this is useful.
ReplyDeleteRegards,
Andrejus
Hi Andrejus,
ReplyDeleteHow to load these files to oracle database in adf .Could you please help
You should use JDBC and BLOB type.
ReplyDeleteAndrejus
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).
ReplyDeleteIt 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.
But this works with my sample app as per screenshot. May be you are missing some steps?
ReplyDeleteRegards,
Andrejus
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.
ReplyDeleteAndrejus
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.
ReplyDeleteYou should increase maximum file size limit.
ReplyDeleteAndrejus
Hi Andrejus,
ReplyDeleteCould 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.
Hi Andrejus,
ReplyDeleteThanks 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,
Hi Andrejus,
ReplyDeleteI 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.
I was planning to use 11gR2 for a new project, but looks like it's missing updates from 11gR1.
ReplyDeleteWhat do you suggest to use 11.1.2.4 or or 11.1.1.7 ?
Thank you
I would suggest 12c, but if it is not possible then 11.1.1.7.
ReplyDeleteAndrejus
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 ?
ReplyDeleteSir,
ReplyDeleteI 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);
}
}
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?
ReplyDeleteHi All,
ReplyDeleteI 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.
Kindly update link to download project. link expired
ReplyDelete
ReplyDeleteYou can download all old samples from here - https://code.google.com/archive/p/jdevsamples/downloads
Andrejus
Hi Andrejus, I faces the same question
ReplyDeleteThanks 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
We are not able to handle mandatory check with required="true" .Looks like it is not working. Any suggestions ?
ReplyDeletethe fragment does not support forms.Therefor how we assign usesuploaded=true
ReplyDeleteEven 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.
ReplyDeleteFor 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.
Hi, I have given maximum size 5
ReplyDeletebut 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.
Hi,
ReplyDeleteIm 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
Yes, it should work on 12c.
ReplyDeleteYou can download all old samples from here - https://code.google.com/archive/p/jdevsamples/downloads
Andrejus