How to access file uploaded via form

I start a process with a form with a file upload.

When I use execution.getVariable(‘uploadedfile’) a number (e.g. 23740) is returned. How can I access the content of the uploaded file?


1 Like

The variable contains the id (e.g. 23740) of the content item stored by the content engine, but how can I access the content item?

Discovered that it is possible to access the content via the rest api (e.g. content-api/content-service/content-items/23740/data).

Another alternative would be ContentService#getContentItemData(String contentItemId), but how can I access the ContentService in a process execution?

The solution is:

InputStream is = ContentEngines.getDefaultContentEngine().getContentService().getContentItemData(execution.getVariable(‘uploadedfile’));

1 Like

When I am using the given script i.e

InputStream is = ContentEngines.getDefaultContentEngine().getContentService().getContentItemData(execution.getVariable(‘propertyfile’));

It is giving me error:

org.flowable.common.engine.api.FlowableException: problem evaluating script: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: ContentEngines for class: Script12
at org.flowable.common.engine.impl.scripting.ScriptingEngines.evaluate( ~[flowable-engine-common-6.3.1.jar:6.3.1]

I am using groovy script format. Can any help me.

Did you use ContentEngines in your script? It seems they are not defined.


HI Martin,

Thanks for your response.
This is the complete code in groovy script which I am trying to run

import org.flowable.*

File file = new File(filepath)
if (propertyfile){
println execution.getVariable('propertyfile')
println propertyfile

InputStream is = ContentEngines.getDefaultContentEngine().getContentService().getContentItemData(execution.getVariable('propertyfile'));

OutputStream outputStream = new FileOutputStream(filepath);
IOUtils.copy(is, outputStream);

The property file is the upload field name. But when I am print it. It is just printing the UUID. The ContentEngines is not working to read the file.

Could you check what is going on in getContentItemData?

At the beginning, create a form with a file upload widget named file and then choose a png image.

Then the following code is working in a groovy script task:

import org.flowable.content.engine.ContentEngines;

file = execution.getVariable('file')
InputStream is = ContentEngines.getDefaultContentEngine().getContentService()

OutputStream outputStream = new FileOutputStream("/tmp/test.png");
IOUtils.copy(is, outputStream);