ng2-file-upload
ng2-file-upload copied to clipboard
is it possible to use http service?
I need upload requests to go through interceptors
Do we have any update on this issue? Because i also need to know to configure it, but i can't figure out.....
@Asargiotakis it's not possible, and no one cares. Look this lib instead https://www.primefaces.org/primeng/#/fileupload
@Viktor-Bredihin do you know how this module uploads a file?? i try to find the way he does the uploading but i cant understand.... Is it using http or httpClient to do the POST? Because i think http (angular/http) is not supported by HttpClient(angular/common/http) interceptor
this module has its proper upload process using the Javascript api xhr in order to optimise and upload your file. If you need to pass an Authorization token, you can use the parameter authToken on ng2FileDrop.
But it could be great to handle interceptor register in Angular5.
Same here - using HTTP interceptors seems like a huge advantage in angular 2/5, and this forced devs to implement some functionality redundantly (like token interceptor).
Would be really useful adaption to have this with the existing nice module.
You can use JWT token like this. It will be attached in headers as Authorization.
this.uploader = new FileUploader({url: URL, queueLimit: 10, authToken: this.authService.getToken()});
There is another simple way to add headers for example instead of using interceptors:
Look at next example adding Bearer Authorization for jwt
uploader: FileUploader = new FileUploader({
url: '<my_url>',
authToken: `Bearer ${my_token}`,
additionalParameter: {
more_data: "foo"
}
});
We use refresh tokens and HTTP interceptor to get new JWT tokens. Sort of the point of Angular and HttpClient. It works perfectly and transparently on all our routes except upload. The intercepter queues requests for the brief time to refresh, so just adding a token to a call and bypass the interceptor will fail from time to time as the JWT expires.
Hello Guys, I have written a new file uploads library that solves this issue, have a look at it: ng-uploader
@harisbarki I am also using this approach, but couldn't make it work with my authToken coming as an Observable. Can you share how you're doing it? Thanks!