how to dynamically change the url in ng2-uploader

1.1k Views Asked by At

I am using ng2-uploader in my angular2 application.

Here is my code:

 options: Object = {
   url: "http://localhost/APP/opsnd/api/index.php/mydkd/configured/?"+JSON.stringify(this.type)
 };

What I did in the above code is that I appended a parameter which is changed dynamically and sent to the server along with the file.

Html:

input type="file" ngFileSelect  [options]="options" (onUpload)="handleUpload($event)" (beforeUpload)="beforeUpload($event)">

The problem is, when I select a file, it is automatically loaded to the server using the default [option] url. So even if the parameters in the url changes, the default url is what is sent to the serve. How can I dynamically change the [options] so that it listens to changes in my component?

1

There are 1 best solutions below

0
On

there is a setOptions() method where you can update your new URL like below,

this.uploader.setOptions({ url: newUrl });

Hope this helps!