Example: Bulk action to download document content
This JavaScript example downloads the document content to a specified directory.
Adapt the following items in the script example:
Output directory | Change the output directory in the script. Because the JavaScript code is executed on a Content Platform Engine server, the content download directory that you specify must satisfy the following requirements:
|
---|
Query example
SELECT TOP 100 This FROM Document
Script example
importClass(Packages.com.filenet.api.collection.ContentElementList);
importClass(Packages.com.filenet.api.core.ContentTransfer);
importClass(java.io.FileOutputStream);
importClass(java.io.InputStream);
importClass(java.lang.Byte);
function OnCustomProcess (CEObject)
{
CEObject.refresh();
var ce = CEObject.get_ContentElements();
if(ce.size() > 0)
{
var ct = ce.get(0);
var folderName = "C://Temp/Content/"; // output directory
this._downloadContent(folderName, ct);
}
}
function _downloadContent(folderName, ct)
{
var out = new FileOutputStream(folderName + ct.get_RetrievalName());
var docLen = ct.get_ContentSize().intValue();
var buf = java.lang.reflect.Array.newInstance(Byte.TYPE, docLen)
var stream = ct.accessContentStream();
stream.read(buf, 0, docLen);
out.write(buf);
out.flush();
stream.close();
out.close();
}