Uploading file, can not get File object

I’m uploading the file with this code:

return $http.get(Uri.appUri('engine://engine/:engine/task/' + camForm.taskId)).success(function(result){
  var formData = new FormData();
  formData.append('data', document.getElementById(fileName).files[0]);
  formData.append('valueType', 'File');
  return $http.post(Uri.appUri('engine://engine/:engine/process-instance/' + result.processInstanceId + '/variables/' + fileName + '/data'), formData, {
      transformRequest: angular.identity,
      headers: {'Content-Type': undefined}


I see the file correct in the Cockpit but I’m getting a ByteArrayInputStream.
I was expecting a FileValue unless I’m wrong.

	FileValue confirmationFile = (FileValue) delegateTask.getVariable("confirmationFile");

I get this error.

Cannot submit task form 49b880b1-b4fe-11e6-ad0d-0a7649bc6e09: ENGINE-03051 There was an exception while invoking the TaskListener. Message: ‘Exception while invoking TaskListener: java.io.ByteArrayInputStream cannot be cast to org.camunda.bpm.engine.variable.value.FileValue’

Any help?


I found that using this worked fine:

	FileValue confirmationFile2 = delegateTask.getVariableTyped("confirmationFile");

Another unrelated issue is that I had to give some small timeout before submitting the form for the variable not to be null for some reason.