0 votes
1.3k views
by (120 points)
I wanted to restrict the files from the bpm file uploader after reaching the files attached size equal to 10 MB. I wanted to find the size of all the files attached without using the Cmis query.

1 Answer

0 votes
by (30.6k points)

The uploader knows the size of every file before it sends it: the browser's File object has size in bytes. Keep a running total in the coach and refuse uploads past the limit - no CMIS query needed:

// UI Toolkit File Uploader "on file selected" / "before upload" event (older toolkits: wrap the input in a custom view)
var LIMIT = 10 * 1024 * 1024;                       // 10 MB
var total = ${Total}.getData() || 0;                // hidden number control / tw.local.uploadedBytes
var f = event && event.file ? event.file : me.context.element.querySelector("input[type=file]").files[0];
if (total + f.size > LIMIT) {
  ${Msg}.setText("Attachments would exceed 10 MB (" + Math.round((total + f.size) / 1048576 * 10) / 10 + " MB)");
  return false;                                     // cancels the upload on toolkits that support it
}
// after a successful upload ("on upload"): ${Total}.setData(total + f.size);

For documents that were uploaded earlier (other tasks), read their sizes once when the coach loads - the BPM document store returns the size without CMIS:

GET /rest/bpm/wle/v1/process/{piid}?parts=documents      -> data.documents[].size (bytes), name, mimeType
// or the Document List control's data: ${DocList}.getData().forEach(function (d) { total += d.size || d.contentSize || 0; });

Server-side (service flow) the same information is tw.system.currentProcessInstance.documents (TWDocument.size) for the BPM document store, and tw.system.ecm / the ECM document properties (cmis:contentStreamLength) for FileNet - that one is a property fetch, not a search query.

References

Related questions

0 votes
1 answer 2.3k views
asked Jul 11, 2020 in Integrations by Abhishek (120 points)
0 votes
1 answer 2.2k views
0 votes
1 answer 2.2k views
0 votes
2 answers 3.7k views
0 votes
1 answer 2.0k views
0 votes
2 answers 4.6k views
0 votes
1 answer 1.9k views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...