# How to access file uploaded via form

**URL:** <https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928>\
**Category:** Flowable Engine\
**Created:** [September 5, 2017, 1:57pm UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928 "2017-09-05T13:57:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PascalSchumacher](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pascalschumacher/32/336_2.png) [@PascalSchumacher](https://forum.flowable.org/u/PascalSchumacher)\
**Post date:** [September 5, 2017, 1:57pm UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/1 "2017-09-05T13:57:25Z")

</div>

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?

Thanks,  
Pascal

---

<div class="post-metadata">

**Author:** ![PascalSchumacher](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pascalschumacher/32/336_2.png) [@PascalSchumacher](https://forum.flowable.org/u/PascalSchumacher)\
**Post date:** [September 6, 2017, 4:28pm UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/2 "2017-09-06T16:28:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![PascalSchumacher](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pascalschumacher/32/336_2.png) [@PascalSchumacher](https://forum.flowable.org/u/PascalSchumacher)\
**Post date:** [September 7, 2017, 11:55am UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/3 "2017-09-07T11:55:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![PascalSchumacher](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pascalschumacher/32/336_2.png) [@PascalSchumacher](https://forum.flowable.org/u/PascalSchumacher)\
**Post date:** [September 7, 2017, 3:37pm UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/4 "2017-09-07T15:37:10Z")

</div>

The solution is:

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

---

<div class="post-metadata">

**Author:** ![sauravInfoObject](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@sauravInfoObject](https://forum.flowable.org/u/sauravInfoObject)\
**Post date:** [October 26, 2018, 11:46am UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/5 "2018-10-26T11:46:25Z")

</div>

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(ScriptingEngines.java:89) ~[flowable-engine-common-6.3.1.jar:6.3.1]

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

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [October 26, 2018, 12:50pm UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/6 "2018-10-26T12:50:40Z")

</div>

> [@sauravInfoObject](#):
>
> ContentEngines

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

Regards  
Martin

---

<div class="post-metadata">

**Author:** ![sauravInfoObject](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@sauravInfoObject](https://forum.flowable.org/u/sauravInfoObject)\
**Post date:** [October 29, 2018, 5:20am UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/7 "2018-10-29T05:20:52Z")

</div>

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);
outputStream.close();
}

```

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.

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [October 29, 2018, 1:04pm UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/8 "2018-10-29T13:04:38Z")

</div>

Could you check what is going on in `getContentItemData`?

---

<div class="post-metadata">

**Author:** ![jckermagoret](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@jckermagoret](https://forum.flowable.org/u/jckermagoret)\
**Post date:** [January 16, 2019, 6:41pm UTC](https://forum.flowable.org/t/how-to-access-file-uploaded-via-form/928/9 "2019-01-16T18:41:51Z")

</div>

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;
import org.apache.commons.io.IOUtils;

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

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