Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending custom headers for each file #11

Closed
danimt opened this issue Jan 28, 2014 · 8 comments
Closed

Sending custom headers for each file #11

danimt opened this issue Jan 28, 2014 · 8 comments

Comments

@danimt
Copy link

danimt commented Jan 28, 2014

Is it possible to send custom headers for each file?

I currently see the option to add extra headers to the global flow object, but that will impact all uploads. In my app I need to send the values pertinent to each uploading file.

Thanks,
Daniel

@AidasK
Copy link
Member

AidasK commented Jan 28, 2014

No, we will need to edit flow.js a bit.
https://github.com/flowjs/flow.js/blob/master/src/flow.js#L1380
Feel free to make a pull request, I think this should be fixed the same way as query parameter: https://github.com/flowjs/flow.js/blob/master/src/flow.js#L1351

@danimt
Copy link
Author

danimt commented Jan 28, 2014

Thank you for your quick response. I'll send a PR as soon as I can work on this. 👍

@danimt
Copy link
Author

danimt commented Feb 6, 2014

I just had time and I realised I don't need to modify the current behaviour.

I can just add the new query parameters by accessing the flowFile.

flowFile.flowObj.opts.query['parameterName'] = 'parameterValue'

Is this the safest way for adding headers?

@AidasK
Copy link
Member

AidasK commented Feb 8, 2014

flowFile.flowObj.opts.query['parameterName'] = 'parameterValue'
In this way, you are changing query parameters for all requests, this is the same as:
flow.opts.query['parameterName'] = 'parameterValue'
or

var flow = new Flow({
  query:{parameterName:'parameterValue'}
});

Although, i suggest using query as a function:

var flow = new Flow({
  query: function (flowFile, flowChunk) {
    // this will be called before every request
    // make some logic with flowFile to add some proper values.
    return {parameterName:'parameterValue'}
  }
});

But this is not supported for headers, a pull request would be needed.

@danimt
Copy link
Author

danimt commented Feb 8, 2014

The way I see it, we could have it either by assigning the parameters to the flowFile, without any control per-chunk, or the query function that would allow for different parameters per-chunk.

Both would be nice, as in some cases I would like to assign the same parameters for all chunks, or change parameters for each chunk.

@AidasK
Copy link
Member

AidasK commented Feb 8, 2014

This is the way to assign parameters per file:

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

Hope this solves your problem.

@danimt
Copy link
Author

danimt commented Feb 11, 2014

Thank you. This works perfectly ;) 👍

This should be documented somewhere to help other users.

@AidasK AidasK closed this as completed Feb 11, 2014
@AidasK
Copy link
Member

AidasK commented May 25, 2014

Added support for custom headers. 67f70d6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants