File upload and download in angular 4 typescript

后端 未结 7 1771
一个人的身影
一个人的身影 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:20

    to download file with angular try with this, it works`

    download(row) {
        return this.Http
          .get(file_path , {
            responseType: ResponseContentType.Blob,
          })
          .map(res => {
            return {
              filename: row.name,
              data: res.blob()
            };
          })
          .subscribe(res => {
            let url = window.URL.createObjectURL(res.data);
            let a = document.createElement('a');
            document.body.appendChild(a);
            a.setAttribute('style', 'display: none');
            a.href = url;
            a.download = res.filename;
            a.click();
            window.URL.revokeObjectURL(url);
            a.remove();
          });
      }
    

    `

提交回复
热议问题