How to add custom headers #654
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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??
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);
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);@HNeukermans I've copied your example exactly and for whatever reason, I still can't get any headers to work, not using
authTokennor 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
withCredentialsfor all items.+1
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"
}]
});