In Groovy script, how to get temporary file from upload widget

Hi all,

When using upload widget, I received a return value like this: {"filename":"1.txt","tempPath":"tmp_17017649110811510037.txt","contentType":"text/plain"}

Searching the server's folder, I found it in folder "\workspace\tomcat\server\temp\bonita_portal_5212@{computer name}\tenants\1".
Is there anyway to dynamically access this file and folder in the Groovy script?

Thanks in advance,

EDIT: As ask below, my case is that user will be allow to upload a text file that is actually a CSV or TSV data file that will appear as link in following tasks, as well as overview page. Before user can submit the form, and save the file to server, they are required to click a button to send the file to a Bonita REST API (Groovy script) that will verify the file and return the result. In this stage, the file is stored in a temporary folder on Bonita folder. I want to, in the REST API Groovy script file, accept a parameter as tempPath value, then access the file in temporary folder, in order to read and check the file data. My problem is how to dynamically access the folder, as the folder name seem to change with each restart.

Thank you for the detailed use case.I now understand your Use case.
I had long back developed a custom REST API that basically check if a file is in correct Excel format .

For this use case , 
You need to modify the Existing Upload widget. Change the Url from API/formFileUpload to your custom REST API.
that custom Widget is now only going to validate.

You need to develop your Own custom REST API. You need Java knowledge. You can refer online forum for the same.
Use the Bonita Studio to create your Own custom REST API. As Input Parameter , pass your Text file. Perform your File validation using Java code inside REST API. Return some output from that custom REST API.
 

Regards

Hello
Could you please provide your Use case in detail ??

It is possible to get the content of the Document in groovy. But that content can be access inside a script Connector or inside a Operation section. 

 You can use the below Class to work with Bonita Documents.


import org.bonitasoft.engine.bpm.document.DocumentValue;

 

You can call the Document variable or contract variable.

Use FileInputStream to read document content and generate a Byte array.
Or convert ByteArray to fileOutputStream.

Does this help.

I have detailed code on how to read documents or Write to external file using Groovy. Will share if required.


Regards
 

 

@ Dibyajit.Roy : Please check the update on my question.

hi , 

can share me a about code read excel file by Groovy ?? Thanks so much. 

Luke

plz share me,too. Thanks