REST API upload a file to a variable

Hello Community,

i instantiated successfully a new process instance with the REST API

I read also in the docs about the file uploading and downloading feature for embedded forms.

Now I want to upload a file with my REST API POST request and make it downloadable with the “downloading files”-tag in a embedded form.

<a cam-file-download="testfile"></a>

The docs says that a variable from the type File in the request body have to encoded as a Base64 string. camunda docs

{
 "variables": {   
     "testfile" : {
         "value": "PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvVFIvaHRtbDQvc3RyaWN0LmR0ZCI+CjxodG1sPgo8aGVhZD4KICA8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUiIGNvbnRlbnQ9InRleHQvaHRtbDsgY2hhcnNldD11dGYtOCI+CiAgPG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1TdHlsZS1UeXBlIiBjb250ZW50PSJ0ZXh0L2NzcyI+CiAgPHRpdGxlPjwvdGl0bGU+CiAgPG1ldGEgbmFtZT0iR2VuZXJhdG9yIiBjb250ZW50PSJDb2NvYSBIVE1MIFdyaXRlciI+CiAgPG1ldGEgbmFtZT0iQ29jb2FWZXJzaW9uIiBjb250ZW50PSIxNTA0LjgzIj4KICA8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgogIDwvc3R5bGU+CjwvaGVhZD4KPGJvZHk+CjwvYm9keT4KPC9odG1sPgo=",
         "type": "String"
     }
 },
 "businessKey" : "myBusinessKey",
 "withVariablesInReturn": true
}

My question is how the request body have to look like to upload a file to a variable and access it with the “downloading files”-tag in a embedded form?

1 Like

I solved the problem with the following request body:

{
 "variables":{
	 "file" : {
     "value": "PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvVFIvaHRtbDQvc3RyaWN0LmR0ZCI+CjxodG1sPgo8aGVhZD4KICA8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUiIGNvbnRlbnQ9InRleHQvaHRtbDsgY2hhcnNldD11dGYtOCI+CiAgPG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1TdHlsZS1UeXBlIiBjb250ZW50PSJ0ZXh0L2NzcyI+CiAgPHRpdGxlPjwvdGl0bGU+CiAgPG1ldGEgbmFtZT0iR2VuZXJhdG9yIiBjb250ZW50PSJDb2NvYSBIVE1MIFdyaXRlciI+CiAgPG1ldGEgbmFtZT0iQ29jb2FWZXJzaW9uIiBjb250ZW50PSIxNTA0LjgzIj4KICA8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgogIDwvc3R5bGU+CjwvaGVhZD4KPGJvZHk+CjwvYm9keT4KPC9odG1sPgo=",
     "type": "File",
	 	 "valueInfo": {
			"filename": "testFile.html",
	 		 "mimetype": "text/html",
	  		"encoding": "UTF-8" 
		 }}
 },
 "businessKey" : "myBusinessKey",
 "withVariablesInReturn": true
}
5 Likes

Hello @J_Christoph_G,

I have a similar requirement.
However, I want to upload on camunda engine a pdf file.
My question is what should the mimetype be?

Another question is how did you parse the value of the file??
I have a js form and I want to parse the value of the file that the user uploads.

Thank you,
Smith.

The mimetype should be “application/pdf”;

variableManager.createVariable({
name: variableName,
type: “Bytes”,
value: valueVariable.file, //here is value of the file you want to save
isDirty: true,
valueInfo: {
filename: valueVariable.name,
mimetype: valueVariable.mimeType
}
});

1 Like