0

I need to pass parameters which are different for each file I used flowobj.opts.query but that adds to all files. Parameters should be different for each file upload

angular.forEach($flow.files, function (file, key) {

    file.flowObj.opts.query[file.DocumentName.concat("-DocumentName")] = file.DocumentName;
    file.flowObj.opts.query[file.DocumentExtension.concat("-DocumentExtension")] = file.DocumentExtension;
    file.flowObj.opts.query[file.DocumentType.concat("-DocumentType")] = file.DocumentType;
    file.flowObj.opts.query[vm.case.Id.concat("-CaseId")] = vm.case.Id;

});

$flow.upload();
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57

2 Answers2

0

From the documentation:

**query** Extra parameters to include in the multipart POST with data. This can be an object or a function. If a function, it will be passed a FlowFile, a FlowChunk object and a isTest boolean (Default: {})

Therefore, just use a function instead of an object as you are doing. Have your function return the object that you want added as parameters.

jle
  • 9,316
  • 5
  • 48
  • 67
0

Old post, but wasn't clear enough without an example for me. So to assign parameters to each file, the best way is to pass a function to the query property that will be evaluate at each chunk, like stated in this issue on github :

var flow = new Flow({
  query: function (flowFile, flowChunk) {
    if (flowFile.myparams) {
      return flowFile.myparams;
    } 
    // generate some values
    flowFile.myparams = {parameterName:'parameterValue'};
    return flowFile.myparams;
  }
});

So for angular it will be set in the provider like this:

var app = angular.module('app', ['flow'])
.config(['flowFactoryProvider', function (flowFactoryProvider) {
  flowFactoryProvider.defaults = {
    query: function(flowfile, flowchunk) {
      if (flowFile.myparams) {
        return flowFile.myparams;
      } 
      // generate some values
      flowFile.myparams = {parameterName:'parameterValue'};
      return flowFile.myparams;
    }
  }

Can also be done in the directive flow-init, I assumed.