0

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'

Shruti Agarwal
  • 887
  • 2
  • 14
  • 29
  • maybe this? https://github.com/valor-software/ng2-file-upload/issues/905 – vegazz Dec 18 '17 at 13:40
  • @vegazz : I am not able to add it to the header. I dont want additional data in body. – Shruti Agarwal Dec 18 '17 at 13:48
  • how about appending the header with your values? may be concat your header with the default one? – Deepak Jha Dec 18 '17 at 13:51
  • @DeepakJha : Yes I want to exactly do that.But I am not able to. can you post a working example if you have. – Shruti Agarwal Dec 18 '17 at 13:54
  • well may be like this headers.concat([{ name: 'foo', value: 'extraHeader'}]), m not sure if this will work but give this a go and let me know if that works. We can try other way as well. – Deepak Jha Dec 18 '17 at 13:56
  • @ShrutiAgarwal any luck? – Deepak Jha Dec 18 '17 at 14:41
  • @DeepakJha : It doesnt work like that. Uploader in ng2-file-upload doesnt give you the options to add headers like that.Please check the module first. – Shruti Agarwal Dec 18 '17 at 15:09
  • @ShrutiAgarwal just seen the document, I wonder if you could write or append headers using the interceptor instead. In my applications I use interceptors to attach custom headers, if your approach hasnt worked as yet try doing it using the interceptor. If need help in writing interceptor let me know I can send some codes to do so . .... – Deepak Jha Dec 19 '17 at 06:07

0 Answers0