Append headers to the upload function in ng2-file-upload

1.2k Views Asked by At

I am using ng2-file-upload in angular2 and have an input field for file and submit button like this :

 <input type="file" ng2FileSelect [uploader]="uploader" />
 <button type="button" class="btn btn-success btn-xs" (click)="item.upload()" [disabled]="item.isReady || item.isUploading || item.isSuccess"> 
    Upload
 </button>

where item is in uploader.queue

In my TS file I have declared uploader like this :

public uploader:FileUploader = new FileUploader(
    {
      url: URL
    }
  );

This seems to work perfectly fine.

But now, I have the requirement to append few headers to this upload function. So, I tried this :

public uploader:FileUploader = new FileUploader(
    {
      url: URL,
      headers: [{ name: 'foo', value: 'extraHeader'}]
    }
  );

which adds foo to my headers but all the other headers like content type:multipart/formdata with boundary are removed and the upload function no longer is able to upload the file.
How can I keep the existing headers added by upload function by default and also be able to add my extra header 'foo'

0

There are 0 best solutions below