cancel
Showing results for 
Search instead for 
Did you mean: 

Attaching file as a form field of custom form UI

shagufta1
Champ in-the-making
Champ in-the-making
I am using Activiti Rest API for fetching, initiating and completing the task. I have my own form UI and there is file attachment field. I am hitting "http://localhost:8080/activiti-app/api/enterprise/task-forms/'+taskId for completing the task. I tried to convert file into JSON text but it gives me bad request error. So what can be solution to upload file as an attachment of a form field via my servlet.
1 ACCEPTED ANSWER

cjose
Elite Collaborator
Elite Collaborator
Even though you are creating the process instance via REST API, attach a start form to the start activity. Keep an attach field in the start form.

Then do the following.
http://localhost:8080/activiti-app/api/enterprise/content/raw [this will upload the content to activiti]
Now start the process instance http://localhost:8080/activiti-app/api/enterprise/process-instances and pass the id value returned by the previous REST call in the request.
For example assume that you get "id": 1001 in response while uploading the content. If your attachment field id in the form is "attach-field", you will need to start the process instance by passing in {"values":{"attach-field":"1001"} in the request.

Hope this helps.

Cheers,

View answer in original post

10 REPLIES 10

shagufta1
Champ in-the-making
Champ in-the-making
Also tried passing the file path directly in JSON but same 400 error and gives me following response.
{
   "message": "Validation of form failed: Illegal related content id: <filePath>",
   "messageKey": "GENERAL.ERROR.BAD-REQUEST"
}

jbarrez
Star Contributor
Star Contributor
The file is uploaded separately via the

POST /enterprise/tasks/{taskId}/raw-content

you get back the id of the content after upload, and need to use that in the form submission.

shagufta1
Champ in-the-making
Champ in-the-making
Yep, Able to send file as Multipart Smiley Happy

Any luck on consuming that file as a process variable?

cjose
Elite Collaborator
Elite Collaborator
As Joram has mentioned, the content is uploaded via a separate api and as part of your form submission the content gets linked to the form field in the RELATED_CONTENT table in database. This attachment data will not be available as part of the process variable.

Cheers,
Ciju

shagufta1
Champ in-the-making
Champ in-the-making
Hi Ciju,

Thanks for your time. So now use case is I want that document(coming from outside) to be displayed as a part of form and after submission of form that document should be a part of process just like Activiti's normal attachment field. Please suggest any workaround if you have.

cjose
Elite Collaborator
Elite Collaborator
Can you please explain the use case in detail? May be a sample bpmn xml or a diagram and a small explanation of the use case with respect to the diagram? That will help me suggest the workaround.

Ciju

shagufta1
Champ in-the-making
Champ in-the-making
Hi,

Consider a simple workflow with single user task… But Initiation of workflow will be via REST APIs… User task will have simple form with only display value fields… All display value fields will display the value of process variables which are passed during initiation of workflow… Now I want to display a document as a form field too… That document also needs to be passed by REST APIs or something else…

cjose
Elite Collaborator
Elite Collaborator
Even though you are creating the process instance via REST API, attach a start form to the start activity. Keep an attach field in the start form.

Then do the following.
http://localhost:8080/activiti-app/api/enterprise/content/raw [this will upload the content to activiti]
Now start the process instance http://localhost:8080/activiti-app/api/enterprise/process-instances and pass the id value returned by the previous REST call in the request.
For example assume that you get "id": 1001 in response while uploading the content. If your attachment field id in the form is "attach-field", you will need to start the process instance by passing in {"values":{"attach-field":"1001"} in the request.

Hope this helps.

Cheers,

joe_l3
Confirmed Champ
Confirmed Champ

Hi,

what you have suggested works for me.

The official documentation does not mention that topic and there is nothing around about how to pass multiple values of the same field (that means multiple attachments).

If you have two or more files previously uploaded, you need to pass a comma separated list of IDs. For example if you have two files with id 1001 and 1002, the Json body in the request should be look like this:

{
"processDefinitionId":"MyProcessDefinition:2:20140",
"values":{"attach-id":"1001,1002"}
}

Thanks.