How to Convert DocumentValue into File (DataType) in Groovy Script

Hello every body,

I trying post form-data (multipart with some files and some part) during the process.
I know how to convert document into documentValue but i need convert documentValue into File.
How can I do that?

Thanks a lot.
Ali

In Continue i resolved it.

`import org.apache.http.HttpResponse
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.mime.MultipartEntity
import org.apache.http.entity.mime.content.FileBody
import org.apache.http.entity.mime.content.StringBody
import org.apache.http.impl.client.HttpClientBuilder
import org.bonitasoft.engine.bpm.document.DocumentValue
import org.bonitasoft.engine.io.IOUtil

@SuppressWarnings(“deprecation”)

// create HTTP Client
def dump = ‘Sucess’;

MultipartEntity entity = new MultipartEntity();

byte content = apiAccessor.getProcessAPI().getDocumentContent(personPic.getId().toString())
String fileName = personPic.getName()
File personPicFile = File.createTempFile(“tmp”, fileName);
IOUtil.write(personPicFile, content);
entity.addPart(“picture”, new FileBody(personPicFile));
personPicFile.delete();

return dump;`

If any other way can help please, share it.

Thanks,
Ali

Hello

Have you tried FileOutputStream. I use outputstream classes to generate any file type i want. Just pass the correct mime type.

Regards

Hi Roy,

In this case i use FileOutputStream :

String encodedContent = passportData.getAt("FaceImageData");
encodedContent.replaceAll("\r", "")
encodedContent.replaceAll("\n", "")
byte[] decodedContent = encodedContent.decodeBase64()

//Convert byte to File
File input = new File("/tmp/img/"+processInstanceId+"_personPic.png");
FileOutputStream fop = new FileOutputStream(input);
fop.write(decodedContent);
fop.flush();
fop.close();

But in above case i have DocumentValue and need Convert into File.

Thanks.
Ali

Thanks for sharing the code.
I hope that anyone else having similar issues will benefit from it.

Thanks

can you please tell how to add jar file of http.entity.mime in bonita studio?