ng2-file-upload icon indicating copy to clipboard operation
ng2-file-upload copied to clipboard

is it possible to use http service?

Open Viktor-Bredihin opened this issue 7 years ago • 10 comments

I need upload requests to go through interceptors

Viktor-Bredihin avatar Dec 26 '17 16:12 Viktor-Bredihin

Do we have any update on this issue? Because i also need to know to configure it, but i can't figure out.....

Davinci-Leonardo avatar Jan 15 '18 14:01 Davinci-Leonardo

@Asargiotakis it's not possible, and no one cares. Look this lib instead https://www.primefaces.org/primeng/#/fileupload

Viktor-Bredihin avatar Jan 15 '18 15:01 Viktor-Bredihin

@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

Davinci-Leonardo avatar Jan 15 '18 19:01 Davinci-Leonardo

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.

Nightbr avatar Feb 05 '18 17:02 Nightbr

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.

mitschmidt avatar Mar 29 '18 12:03 mitschmidt

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()}); screen shot 2018-07-06 at 10 43 26 pm

harisbarki avatar Jul 07 '18 01:07 harisbarki

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"
    }
  });

WindSaber avatar Jul 19 '18 18:07 WindSaber

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.

sumpton avatar Mar 04 '19 15:03 sumpton

Hello Guys, I have written a new file uploads library that solves this issue, have a look at it: ng-uploader

omardoma avatar Jul 09 '19 02:07 omardoma

@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!

dvyue avatar Dec 05 '19 10:12 dvyue