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

1
0
-1

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.

Comments

Submitted by Dibyajit.Roy on Mon, 04/18/2022 - 16:35

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

Submitted by ndhv1983_2529106 on Tue, 04/19/2022 - 04:32

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

Submitted by Kluke on Mon, 03/11/2024 - 03:23

hi ,

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

Luke

Submitted by Kluke on Mon, 03/11/2024 - 03:25

plz share me,too. Thanks

1 answer

1
0
-1
This one is the BEST answer!

<p>Thank you for the detailed use case.I now understand your Use case.<br />
I had long back developed a custom REST API that basically check if a file is in correct Excel format .<br />
<br />
For this use case ,&nbsp;<br />
You need to modify the Existing Upload widget. Change the Url from&nbsp;API/formFileUpload&nbsp;to your custom REST API.<br />
that custom Widget is now only going to validate.</p>

<p>You need to develop your Own custom REST API. You need Java knowledge. You can refer online forum for the same.<br />
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.<br />
&nbsp;</p>

<p>Regards</p>

Notifications