3

I am using JDeveloper. Within an ADF Fusion Web Application I have an Input File control and a Send button which calls a bean method to upload the file to the UCM. If my file is located on my machine, let's say "/home/user/myfile.txt", it works like a charm. If I am trying to use a Input File, I do not see anywhere how to upload the file to the UCM without first saving this file to the disk and then upload this file. In my opinion, this way of doing thing is not recommended.

Here is the code I have so far which is able to upload a file coming from the server workstation :

// RETRIEVE THE DESTINATION PATH
DataBinder binder = idcClient.createBinder();
binder.putLocal("IdcService", "COLLECTION_INFO");
binder.putLocal("hasCollectionPath", "true");
binder.putLocal("dCollectionPath", "/Contribution Folders/PDD"); // The path you are looking for
DataBinder searchFolder = idcClient.sendRequest(idcContext, binder).getResponseAsBinder();

binder = idcClient.createBinder();
binder.putLocal ("IdcService", "CHECKIN_NEW");
binder.putLocal ("dDocAuthor", "weblogic");
binder.putLocal ("dDocTitle", "myimage2.jpg");
binder.putLocal ("dDocName", "myimage2.jpg");
binder.putLocal ("dDocType", "Document");
binder.putLocal("xCollectionID", searchFolder.getLocal("dCollectionID"));
binder.putLocal ("dSecurityGroup", "Public");
binder.putLocal ("dDocAccount:", "");
binder.putLocal ("xComments", "My comment");
binder.addFile ("primaryFile", new File("/home/oracle/myimage.jpg"));

// check in the file
ServiceResponse response = idcClient.sendRequest (idcContext, binder);

If you have any suggestion, I would appreciate a lot. Thanks guys!


Here is the solution :

        UploadedFile uf = (UploadedFile) inputFile1.getValue();

        DataBinder binder = idcClient.createBinder();
        binder.putLocal ("IdcService", "CHECKIN_NEW");
        binder.putLocal ("dDocAuthor", "weblogic"); // if user is admin, can specify other user
        binder.putLocal ("dDocTitle", uf.getFilename());
        binder.putLocal ("dDocName", uf.getFilename());
        binder.putLocal ("dDocType", "DigitalMedia");
        binder.putLocal("xCollectionID", getFolderCollectionId("/Contribution Folders/PDD")); // parent's folder
        binder.putLocal ("dSecurityGroup", "Public");
        binder.putLocal ("dDocAccount:", "");
        binder.putLocal ("xComments", "Montreal comment");
        binder.putLocal ("xWCTags", "Montreal");

        binder.addFile ("primaryFile", new TransferFile(uf.getInputStream(), uf.getFilename(), getByteLenght(uf.getInputStream())));

        ServiceResponse response = idcClient.sendRequest (idcContext, binder);
Benster
  • 91
  • 2
  • 4
  • Where are those files stored then if they are not on your machine? – User404 Oct 27 '12 at 07:59
  • When you use a InputFile control and the user browses for a file, it gives you an InputStream. What I would like, is a way to send this inputstream to the UCM without having to save the file first on the server which seems to be a bad practice to me. – Benster Oct 29 '12 at 17:20
  • The only possible way is converting the inputstream to a File since the UCM Api only accepts File objects. You can always delete the File after uploading of course. Ex: File f = new File(); //upload f.delete(); – User404 Oct 29 '12 at 21:05
  • 2
    I have found a solution on my own. I saw earlier that this RIDC API accepted a TransferFile as well. The only thing missing was a way to get the size of the InputStream. I found a piece of code for doing this and now it finally worked. UploadedFile uf = (UploadedFile) if1.getValue(); DataBinder binder = idcClient.createBinder(); binder.putLocal ("IdcService", "CHECKIN_NEW"); ... binder.addFile ("primaryFile", new TransferFile(uf.getInputStream(), uf.getFilename(), getByteLenght(uf.getInputStream()))); – Benster Oct 30 '12 at 16:06

1 Answers1

2

You've found solution by yourself already so I just want to mention that there are other handy UploadFile methods that should be used here.

getFilename(); //you've got this
getLength(); //instead of getting byte length from stream
getContentType(); //available MIME

Is your getFolderCollectionId("/Contribution Folders/PDD")) working as intended?

Also keep in mind that file is stored in memory only if its size is less than 100KB and written to the disk if more. Each request limit is 2000KB. These are default values and can be changed in servlet context initialization parameters.

<context-param>
    <!-- Maximum memory per request (in bytes) -->
    <param-name>oracle.adf.view.faces.UPLOAD_MAX_MEMORY</param-name>
    <param-value>512000</param-value>
</context-param>
<context-param>
    <!-- Maximum disk space per request (in bytes) -->
    <param-name>oracle.adf.view.faces.UPLOAD_MAX_DISK_SPACE</param-name>
    <param-value>5120000</param-value>
</context-param>
<context-param>
    <!-- directory to store temporary files -->
    <param-name>oracle.adf.view.faces.UPLOAD_TEMP_DIR</param-name>
    <param-value>/tmp/ADFUploads/</param-value>
</context-param>

<!-- This filter is always required by ADF;  one of its functions is file upload. -->
<filter>
    <filter-name>adfFaces</filter-name>
    <filter-class>oracle.adf.view.faces.webapp.AdfFacesFilter</filter-class>
</filter>
arkonautom
  • 958
  • 18
  • 29
  • The question, comments, and answer to this @Benster post are spot on. Indeed using `new TransferFile(file.getInputStream(), file.getFilename(), file.getLength(), file.getContentType()` works perfectly. See also [basic links](http://docs.oracle.com/cd/E10316_01/ContentIntegration/ridc/Javadoc/oracle/stellent/ridc/model/TransferFile.html). – 32U Jan 10 '14 at 00:09