【发布时间】:2013-11-02 01:32:21
【问题描述】:
我正在使用 JDeveloper。在 ADF Fusion Web 应用程序中,我有一个 Input File 控件和一个 Send 按钮,它调用 bean 方法将文件上传到 UCM。如果我的文件位于我的机器上,比如说“/home/user/myfile.txt”,它就像一个魅力。如果我尝试使用输入文件,我看不到如何将文件上传到 UCM,而无需先将此文件保存到磁盘然后上传此文件。在我看来,不推荐这种做事方式。
这是我目前能够上传来自服务器工作站的文件的代码:
// 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);
如果您有任何建议,我将不胜感激。 谢谢大家!
解决办法如下:
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);
【问题讨论】:
-
如果这些文件不在您的机器上,它们会存储在哪里?
-
当您使用 InputFile 控件并且用户浏览文件时,它会为您提供 InputStream。我想要的是一种将此输入流发送到 UCM 的方法,而无需先将文件保存在服务器上,这对我来说似乎是一种不好的做法。
-
唯一可能的方法是将输入流转换为文件,因为 UCM Api 只接受文件对象。当然,您可以在上传后随时删除文件。例如:文件 f = new File(); //上传 f.delete();
-
我自己找到了解决方案。我之前看到这个 RIDC API 也接受了一个 TransferFile。唯一缺少的是获取 InputStream 大小的方法。我找到了一段代码来做这件事,现在它终于奏效了。 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())));
标签: file-upload oracle-adf oracle-ucm