File upload and download in angular 4 typescript

后端 未结 7 1781
一个人的身影
一个人的身影 2020-12-13 10:58

How can I download (.exe file which is in root path) and Upload a file from Angular 4?
I am new to Angular4 and typescript and .NET Core Web API.

I h

7条回答
  •  清歌不尽
    2020-12-13 11:14

    Select image to upload:
    import { Component, OnInit } from '@angular/core';
    import { FormControl, FormGroup } from '@angular/forms';
    import { HttpClient } from '@angular/common/http';
    @Component({
      selector: 'app-praveen',
      templateUrl: './praveen.component.html',
      styleUrls: ['./praveen.component.css']
    })
    export class PraveenComponent implements OnInit {
    
      constructor(private httpClient:HttpClient) { }
        uploadForm = new FormGroup ({
            file1: new FormControl()
        });
        filedata:any;
        fileEvent(e){
            this.filedata=e.target.files[0];
            console.log(e);
        }
        onSubmit() {
            let formdata = new FormData();
            console.log(this.uploadForm)
            formdata.append("avatar",this.filedata);
            this.httpClient
            .post("http://localhost:3040/uploading",formdata)
            .subscribe((res)=>{console.log(res});
        }
      ngOnInit() {
      }
    
    }
    

提交回复
热议问题