Hello,
I have a task in which users can upload a file in a form.
Later i have an service task that creates a folder on the user computer thanks to a groovy script. These parts work fine.
But, I would like to automaticly download in this new folder the file that has been uploaded by the user in the first human task, and i can't figure out how to do this...
Can someone explain to me how to do ?
Thank you very much.
I'm using last version of Bonita Studio and Java version 7.
Hi Julien,
so you have your file stored on a bonita document object , right?
You can use this code inside a groovy script:
ProcessApi processAPI = apiAccessor.getProcessAPI();
byte[] content = processAPI.getDocumentContent(document.getContentStorageId());
FileOutputStream fos = new FileOutputStream("your directory here");
fos.write(content);
Cheers!
Hi, thank you for your answer, but it still doesn't work...
When i test the script, i get this :
java.lang.reflect.InvocationTargetException
org.bonitasoft.engine.bpm.connector.ConnectorExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression cdc with content: import org.bonitasoft.engine.api.ProcessAPI;
ProcessAPI processAPI = apiAccessor.getProcessAPI();
byte[] content = processAPI.getDocumentContent(document.getContentStorageId());
FileOutputStream fos = new FileOutputStream('C:/Users/jetienvre/Documents'); fos.write(content); depends on document is neither defined in the script nor in dependencies
Enrico: I can use that bos file too.
Freddy.Kugelmass@imm.gub.uy
Thanks!
Thank you, but i still don't get my file in my folder...
Groovy can't resolve document1 variable. I don't understand what is document1 ?
I get this result :
java.lang.reflect.InvocationTargetException
org.bonitasoft.engine.bpm.connector.ConnectorExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression copy cdc with content: import org.bonitasoft.engine.api.ProcessAPI;
ProcessAPI processAPI = apiAccessor.getProcessAPI();
byte[] content = processAPI.getDocumentContent(document.getContentStorageId());
FileOutputStream fos = new FileOutputStream('C:/Users/jetienvre/Dekstop/myFile.txt');
fos.write(content); depends on document is neither defined in the script nor in dependencies
Thank you.
document1 is the name of the Document you create at the pool level. I can share you an example bos file if you give me your email
Ok, thank you, my email is julienetienvre@gmail.com
Hi Julien, there was an error in my script, try with this one:
import org.bonitasoft.engine.api.ProcessAPI;
ProcessAPI processAPI = apiAccessor.getProcessAPI();
byte[] content = processAPI.getDocumentContent(document1.getContentStorageId());
FileOutputStream fos = new FileOutputStream(filePath);
fos.write(content);
return "OK";
the filePath variable is not a directory, but it's a file name (for instance under windows: C:/temp/myFile.xlsx)
I put this code on a groovy script inside an operation. The result of the script (OK) is mapped to a process variable and can be checked on some other steps
If you have other problems please cut and paste all the stack trace.
Cheers