2

I am using ember vesrion 2.15.1 for my application. I am using ember-file-upload node module to support file upload and that is successful. Challenge is I am not able to add auth token to the request header. My request header looks like this:

enter image description here I am not able to add userAuthToken in request header of file upload like below which I am able to add for other api calls:

enter image description here

I have tried uploading the file via

set(file, 'headers.userAuthToken', localStorage.getItem("userToken")); // this line is creating problems
let response = yield file.upload(url);

But unable to add userAuthToken in request header. Any fix or workaround will be appreciated.

Anand Gupta
  • 5,640
  • 3
  • 27
  • 37

2 Answers2

3

You can pass options as second parameter of upload method. One of possible options is headers. Something like this should work:

let response = yield file.upload(url, {
  headers: {userAuthToken: localStorage.getItem("userToken")}
});

You can find other possible options here

Gennady Dogaev
  • 5,902
  • 1
  • 15
  • 23
0

You can add additional headers in application adapter, for example:

import ActiveModelAdapter from 'active-model-adapter';

var token = $('meta[name="csrf-token"]').attr('content');

export default ActiveModelAdapter.extend({
    headers: {
        "X-CSRF-Token": token
    }
});