简体   繁体   中英

how to dynamically change the url in ng2-uploader

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?

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

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

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM