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 http://community.bonitasoft.com/project/file-upload-and-download-process-example)
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))

	filesInputValue.add(fileInputValue)
}
index += numberOfResult

}

filesInputValue.addAll(myMultipleDocumentsContract);

return filesInputValue


Thanks,
Raphael.

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 http://community.bonitasoft.com/project/file-upload-and-download-process)
I’m using BonitaBPMCommunity-7.3.3
Code 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 (supportingDocDeleteContract.isEmpty() == false){
for (Map<String, Object> documentToDelete : supportingDocDeleteContract){
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, “supportingDocuments”, index, numberOfResult)).size()) {
for(Document currentDocument : documents) {
FileInputValue fileInputValue = new FileInputValue(currentDocument.contentFileName, apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))

	filesInputValue.add(fileInputValue)
}
index += numberOfResult

}

filesInputValue.addAll(supportingDocContract);

return filesInputValue

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 (http://documentation.bonitasoft.com/javadoc/api/7.3/org/bonitasoft/engine/bpm/contract/FileInputValue.html):

Constructor Detail

FileInputValue (2 values expected)
public FileInputValue(String fileName,
byte content)

FileInputValue (3 values expected)
public FileInputValue(String fileName,
String contentType,
byte content)

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

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

or something like it :slight_smile:

regards
Seán

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

Hi Sean,

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

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)

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:

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
Seán

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…

regards