Hello All :)
Previously I have posted about uploading and downloading files from server path (Refer this post for more clarification), In that post I have described the process of uploading single file at a time but sometimes we need to upload multiple files at a time and for that requirement we can use same code with little modification
So In this post we'll see that how can we upload multiple files at a time using af:inputFile, Here I am using same sample application that is used in previous post
Default inputFile source looks like this
<af:inputFile label="Select" id="if1" valueChangeListener="#{viewScope.FileUploadDownloadBean.uploadFileVCE}" autoSubmit="true"/>
To enable multiple files selection in af:inputFile we have to set some properties
<af:inputFile label="Select" id="if1" valueChangeListener="#{viewScope.FileUploadDownloadBean.uploadFileVCE}" autoSubmit="true" rows="5" maximumFiles="5"/>
and what rows and maximumFiles properties means ?
rows | int | Yes | an attribute that determines the number of rows in the file list. There will be a scrollbar which will be displayed when the number of files exceeds this number. |
maximumFiles | int | Yes | an attribute that is used to restrict the number of files a user can upload. If the user tries to upload more files than specified in maximumFiles then an error is returned. If maximumFiles is less than 1 then the number of files is unlimited. |
After setting these properties inputFile looks like this
Now UI part is done , next is code part so to get and upload multiples files from client we have to use a List data structure and then in value change listener we'll traverse that List and upload all files to server path.
ValueChangeListener of af:inputFile-
/*****Generic Method to Get BindingContainer**/ public BindingContainer getBindingsCont() { return BindingContext.getCurrent().getCurrentBindingsEntry(); } /** * Generic Method to execute operation * */ public OperationBinding executeOperation(String operation) { OperationBinding createParam = getBindingsCont().getOperationBinding(operation); return createParam; } /**Method to Upload Multiple Files ,called on ValueChangeEvent of inputFile * @param vce */ public void uploadFileVCE(ValueChangeEvent vce) { if (vce.getNewValue() != null) { //Get File Object from VC Event List<UploadedFile> lf = (List<UploadedFile>) vce.getNewValue(); //Traverse over file list to upload all files for (UploadedFile fileVal : lf) { //Method to check if this file is uploaded previously or not OperationBinding duplOb = executeOperation("checkDuplicateFile"); duplOb.getParamsMap().put("fileNm", fileVal.getFilename()); duplOb.execute(); if (duplOb.getResult() != null && "Y".equalsIgnoreCase(duplOb.getResult().toString())) { System.out.println("Called"); //Upload File to path- Return actual server path String path = uploadFile(fileVal); System.out.println(fileVal.getContentType()); //Method to insert data in table to keep track of uploaded files OperationBinding ob = executeOperation("setFileData"); ob.getParamsMap().put("name", fileVal.getFilename()); ob.getParamsMap().put("path", path); ob.getParamsMap().put("contTyp", fileVal.getContentType()); ob.execute(); } } // Reset inputFile component after upload ResetUtils.reset(vce.getComponent()); } }
AMImpl Method to check duplicate file-
/**Method to check for duplicate files * @param fileNm * @return */ public String checkDuplicateFile(String fileNm) { ViewObject fileVo = this.getFileUpdDwn1(); Row duplFile[] = fileVo.getFilteredRows("FileName", fileNm); if (duplFile.length > 0) { return "N"; } else { return "Y"; } }
For other methods and DB table refer previous post Uploading and downloading files from absolute server path
So All done for multiple files upload now run and check application
Sample ADF Application (Jdeveloper 12.1.3)- Download
Cheers :) Happy Learning
Hi Sir,
ReplyDeleteI have a concern irrespective to this blog. Actually when i run my application on integrated weblogic in jdeveloper 12c it got deployed(run) successfully but when 2nd time when i run the same application rather then redeploying, it got undeployed. Am facing this issue on alternate basis everytime and on every machine.
Thanks in advance.
Hi Rahul
DeleteClean and rebuild application , delete .data folder in application directory , delete application from drs folder and check again
Ashish
nice work Ashish
ReplyDeleteBut i have a small problem
when i upload *.txt or *.csv or * .jpg ...etc. i can see the file content in inlineFrame without any problems, but when i upload *.docx or *.xlsx and click on the file to see it's content i get download operation with Zip file and this zip file has the same name of the servlet
Hi Mariam
DeleteWe can not directly show docx and XLS file in web page , A plugin is required to show these types and I have never implemented this
So you can put a question in OTN Forum
Ashish
and when i try to download *.xlsx or *.docx the download process is working fine but i get another download file with the same name of servlet also
ReplyDeleteThat's because of inline frame , set render false for inline frame in case of file type is docx or xls
Deletethanks ashish
ReplyDeletebut I have another problem
when I apply this post in Jspx page it was working fine
but when I try to apply it into jsff page(dynamic region with task flow)
I got this error
"#{bindings.dynamicRegion1.regionModel}" (that was specified for the RegionModel "value" attribute of the region component with id "r1") evaluated to null.
This is typically due to an error in the configuration of the objects referenced by this expression.
If it helps, the expression "#{bindings.dynamicRegion1}" evaluates to "null".
If it helps, the expression "#{bindings}" evaluates to "null". Now using an empty RegionMode
Hi Mariam
DeleteSo you have used this code in jsff page and dropped that BTF as dynamic region in a jspx page ?
Once check that definition for region in available in pagedef or not ?
Ashish
Hi Mariam , be sure that Jsp page property ( usesupload = true)
ReplyDeleteI like you application it's vary good
ReplyDeletehi Sir,
ReplyDeleteI would like to save to DB using a button, not as the above, would you please advise how to separate above code
//Method to insert data in table to keep track of uploaded files
OperationBinding ob = executeOperation("setFileData");
ob.getParamsMap().put("name", fileVal.getFilename());
ob.getParamsMap().put("path", path);
ob.getParamsMap().put("contTyp", fileVal.getContentType());
thank you :)
You need to call same on button click and to get af:inputFile value on button you need to bind it to bean using a variable, You can check this post
DeleteUploading and showing image file from absolute server path -Orace ADF
Here you'll see that a variable is used to get file value
Ashish
Hi Ashish,
ReplyDeleteGetting 404 while downloading the sample from : https://drive.google.com/uc?export=download&id=0B0Usl2n1Wz8vNTJJTVZLUENIMmM.
Could you provide a working url?
Thanks,
Sapna
Checked link is working for me, Once check again please :)
DeleteIt doesn't work. Getting error 404
DeleteCan you please update the download link? Thank you in advance!
ReplyDeleteYes I checked there is some problem with Google policies
DeleteYou can share your email id so that i can send you the sample app
Ashish
radutudorion@gmail.com
DeleteMaybe upload to wetransfer and send the link, if google blocks java code as malicious(it happens sometimes)
DeleteThank you!
DeleteYou are welcome TheDarkSideOfSugar :)
DeleteHi Ashish,
ReplyDeleteI have referred your sample for multiple file upload,
When I am uploading 11 files its sucessfull
When I am uploading 25 + files it is throwing 503 error(A connection to server has failed : Status 503)
in the log file I am seeing some multithreading issue.
Can you help in this regard, how to escape from 503 error.
Regards,
Shikha
Hi,
ReplyDeleteCan I please receive the download link?
Thanks,
Bogdan.
this is a great work Ashish , so how can save all this photos in database in same time and every photo in different row and different id
ReplyDeleteHi Mohamed
DeleteCheck this post and use methods accrodingly
Uploading and downloading files from database (BLOB) in Oracle ADF (12.1.3)
Ashish
Hi Ashish.. please you can send me a email with the project to alarconignaciojuan@gmail.com?
ReplyDeleteThe download link is broken.
Regards
Juani
DeleteCheck the link again, I have fixed that
Ashish
Hi Ashish. Thanks..
DeleteHi sir , i used your sample and i set input_file-> maximumfiles = 25 , but i can't upload more than three or four file ? please help
ReplyDeleteIs there any error in log ?
DeleteHave you checked sample application ?
I checked it , and no error ,it's like your video notice you choose four files but only three files are uploaded its like that
Delete