REST API upload a file to a variable


#1

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?


#2

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
}