contentMimeType becomes null when Document is updated


I've created a document under Data and I am able to add and delete the files (I followed the example in
When the following script is run in Operations to update an attached Document, the contentMimeType gets updated from application/pdf to null.
As a result of this change, I can't send an email with the Documents attached as I get the error org.bonitasoft.engine.connector.ConnectorException: javax.mail.internet.ParseException: Expected MIME type, got null"

How can I get the contentMimeType not to change its value?

Script below:
import java.util.logging.Logger;

import org.bonitasoft.engine.bpm.contract.FileInputValue
import org.bonitasoft.engine.bpm.document.Document
import org.bonitasoft.engine.bpm.document.DocumentValue

if(myMultipleDocumentsDeleteContract.isEmpty() == false) {
for(Map<String, Object> documentToDelete : myMultipleDocumentsDeleteContract) {
if(documentToDelete.get("selected")) {
apiAccessor.processAPI.removeDocument(documentToDelete.get("id") as long);

int index = 0
int numberOfResult = 1
List documents
List filesInputValue = new ArrayList()

while((documents = apiAccessor.processAPI.getDocumentList(processInstanceId, "myMultipleDocuments", index, numberOfResult)).size()) {
for(Document currentDocument : documents) {
FileInputValue fileInputValue = new FileInputValue(currentDocument.contentFileName, apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))

index += numberOfResult



return filesInputValue



Submitted by Sean McP on Mon, 01/23/2017 - 04:32

A Tip on displaying CODE/LOGS correctly in Posts:

Do not use the Supplied Buttons above, for some reason they refuse to work correctly, and despite bringing it to Bonitasofts attention, it's low priority.

To Show Code/Logs correctly use

< code >
your code/log
< /code >

removing the spaces to allow the showing of code/logs correctly as here:

  1. your code/log

You should still be able to edit your post to ensure the correct formatting of the code to help us understand it easier.

Thanks and regards

3 answers

This one is the BEST answer!

Hi Sean,

Thanks for the answer. It solved the problem.I used currentDocument.contentMimeType in the constructor. The code below

  1. FileInputValue fileInputValue = new FileInputValue(currentDocument.contentFileName, currentDocument.contentMimeType, apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))

This is solved but I don't know how to mark it as resolved (I'm a newbie)


Submitted by Sean McP on Tue, 01/24/2017 - 23:46

Against my answer on the left of the box there is a Tick mark next to the up/down 0 (up/down rating). Just click on the big tick mark...



Just realized what you are doing...

You are "copying" a file to another to another file...

What you've not realized though is that it doesn't copy the mime type with the file, you have to do it yourself, or use the correct call...

from the documentation (

  1. Constructor Detail
  3. FileInputValue (2 values expected)
  4. public FileInputValue(String fileName,
  5. byte[] content)
  7. FileInputValue (3 values expected)
  8. public FileInputValue(String fileName,
  9. String contentType,
  10. byte[] content)

If you use the second type of call referencing the original document then it will work:

  1. FileInputValue fileInputValue = new FileInputValue(currentDocument.contentFileName,
  2. apiAccessor.processAPI.getContentType(currentDocument.contentStorageId),
  3. apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))

or something like it :)


PS: As this reply answers your question, please mark as resolved.


Thanks Sean for the tip, the script (using   as advised) which I believe is changing the value of contentMimeType to null for Documents uploaded to a case (I got the code from the example in
I'm using BonitaBPMCommunity-7.3.3
Code below:

  1. import java.util.logging.Logger;
  3. import org.bonitasoft.engine.bpm.contract.FileInputValue
  4. import org.bonitasoft.engine.bpm.document.Document
  5. import org.bonitasoft.engine.bpm.document.DocumentValue
  7. if (supportingDocDeleteContract.isEmpty() == false){
  8. for (Map<String, Object> documentToDelete : supportingDocDeleteContract){
  9. if (documentToDelete.get("selected")){
  10. apiAccessor.processAPI.removeDocument(documentToDelete.get("id")as long)
  11. }
  12. }
  13. }
  14. int index = 0
  15. int numberOfResult = 1
  16. List<Document> documents
  17. List<FileInputValue> filesInputValue = new ArrayList<FileInputValue>()
  19. while((documents = apiAccessor.processAPI.getDocumentList(processInstanceId, "supportingDocuments", index, numberOfResult)).size()) {
  20. for(Document currentDocument : documents) {
  21. FileInputValue fileInputValue = new FileInputValue(currentDocument.contentFileName, apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))
  23. filesInputValue.add(fileInputValue)
  24. }
  25. index += numberOfResult
  26. }
  28. filesInputValue.addAll(supportingDocContract);
  30. return filesInputValue