ASP.NET Core 2.0 and Angular 4.3 File Upload with progress -


using new angular 4.3 httpclient, how can upload , access files in asp.net core 2.0 controller while reporting upload progress client?

here working example started:

html

<input #file type="file" multiple (change)="upload(file.files)" /> <span *ngif="uploadprogress > 0 && uploadprogress < 100">     {{uploadprogress}}% </span> 

typescript

import { component } '@angular/core'; import { httpclient, httprequest, httpeventtype, httpresponse } '@angular/common/http'  @component({     selector: 'files',     templateurl: './files.component.html', }) export class filescomponent {     public uploadprogress: number;      constructor(private http: httpclient) { }      upload(files) {         if (files.length === 0)             return;          const formdata = new formdata();          (let file of files)             formdata.append(file.name, file);          const req = new httprequest('post', `api/files`, formdata, {             reportprogress: true,         });          this.http.request(req).subscribe(event => {             if (event.type === httpeventtype.uploadprogress)                 this.uploadprogress = math.round(100 * event.loaded / event.total);             else if (event instanceof httpresponse)                 console.log('files uploaded!');         });     } } 

controller

[httppost, disablerequestsizelimit, route("api/files")] public async task uploadfiles() {     var files = request.form.files; // have them } 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -