How to add custom headers #654

Open
opened 2017-03-02 23:27:14 +00:00 by vicmac-zz · 5 comments
vicmac-zz commented 2017-03-02 23:27:14 +00:00 (Migrated from github.com)

Hey guys!

I'm experimenting with this module, the problem is I can't set the custom headers. So far I did this

import { Component } from '@angular/core';
import { FileUploader, Headers } from 'ng2-file-upload';

@Component({
moduleId: module.id,
selector: 'sg-uploadcompnent',
templateUrl: '../views/upload-documents.template.html'
})

export class UploadDocumentsComponent {

public uploader: FileUploader = new FileUploader({
url: "http://localhost:port/app/api/upload/",
authToken: "Authorization",
authTokenHeader: "Bearer mytoken871lkdk39829",
isHTML5: true,
headers: [
{name: "myCustomHeader", value:"some value"}
]

});
}

But unfortunately, when I click on the button submit (I'm using the same as the demo), I can't see the request headers in the request.

I'm using ng2-file-upload 1.2.0 version

Any ideas??

Hey guys! I'm experimenting with this module, the problem is I can't set the custom headers. So far I did this import { Component } from '@angular/core'; import { FileUploader, Headers } from 'ng2-file-upload'; @Component({ moduleId: module.id, selector: 'sg-uploadcompnent', templateUrl: '../views/upload-documents.template.html' }) export class UploadDocumentsComponent { public uploader: FileUploader = new FileUploader({ url: "http://localhost:port/app/api/upload/", authToken: "Authorization", authTokenHeader: "Bearer mytoken871lkdk39829", isHTML5: true, **headers: [ {name: "myCustomHeader", value:"some value"} ]** }); } But unfortunately, when I click on the button submit (I'm using the same as the demo), I can't see the request headers in the request. I'm using **ng2-file-upload 1.2.0 version** Any ideas??
plima2050 commented 2017-03-07 20:47:34 +00:00 (Migrated from github.com)

Hi, @vicmac try this work fine. I hope help you.

this.uploader = new FileUploader({});
this.uploaderOptions['url'] = URL;
this.uploaderOptions['method'] = 'POST';
this.uploaderOptions['autoUpload'] = false;
this.uploader.setOptions(this.uploaderOptions);

Hi, @vicmac try this work fine. I hope help you. this.uploader = new FileUploader({}); this.uploaderOptions['url'] = URL; this.uploaderOptions['method'] = 'POST'; this.uploaderOptions['autoUpload'] = false; this.uploader.setOptions(this.uploaderOptions);
HNeukermans commented 2017-04-13 13:22:01 +00:00 (Migrated from github.com)

Above answer did not work for me.
This works for me:
var uo: FileUploaderOptions = {};
uo.headers = [{ name: 'x-ms-blob-type', value : 'BlockBlob' } ]
this.uploader.setOptions(uo);

Above answer did not work for me. This works for me: ` var uo: FileUploaderOptions = {};` ` uo.headers = [{ name: 'x-ms-blob-type', value : 'BlockBlob' } ]` ` this.uploader.setOptions(uo);`
mcblum commented 2017-11-21 21:37:56 +00:00 (Migrated from github.com)

@HNeukermans I've copied your example exactly and for whatever reason, I still can't get any headers to work, not using authToken nor specifying the exact headers. They are simply not in the request.

If you have any ideas, let me know! Thanks for the tip either way.

Edit: never mind! Just needed to do what's suggested and disable withCredentials for all items.

@HNeukermans I've copied your example exactly and for whatever reason, I still can't get any headers to work, not using `authToken` nor specifying the exact headers. They are simply not in the request. If you have any ideas, let me know! Thanks for the tip either way. Edit: never mind! Just needed to do what's suggested and disable `withCredentials` for all items.
yuwu9145 commented 2018-04-22 03:48:43 +00:00 (Migrated from github.com)

+1

+1
sakiv commented 2018-05-29 06:46:59 +00:00 (Migrated from github.com)

Thanks....this worked for me....only mistake was that authTokenHeader and authToken should be swapped.

public uploader: FileUploader = new FileUploader({
url: "http://localhost:port/app/api/upload/",
authTokenHeader: "Authorization",
authToken: "Bearer mytoken871lkdk39829",
isHTML5: true,
headers: [{
name: "myCustomHeader",
value: "some value"
}]
});

Thanks....this worked for me....only mistake was that authTokenHeader and authToken should be swapped. public uploader: FileUploader = new FileUploader({ url: "http://localhost:port/app/api/upload/", **_authTokenHeader_**: "Authorization", **_authToken_**: "Bearer mytoken871lkdk39829", isHTML5: true, headers: [{ name: "myCustomHeader", value: "some value" }] });
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#654