angular - Angular 9 Opening file saved in database with the fileName retrieved from database
问题描述
I have file stored in database table with the contents(bytes), fileName, contentType. I want the file to open in new tab when clicked in the Angular side with the fileName that is retrieved from database. My file opens in the new tab but how can I give the fileName to it.
//Service
downloadDoc(Id: string): Observable<any> {
let url = this.APIUrl + Id + '/doc';
let headers: HttpHeaders = new HttpHeaders();
return this.http.get(url, { headers: headers, responseType: 'blob' });
}
//Component
getDoc(id: any) {
this.service.downloadDoc(id).subscribe((result) => {
var url = window.URL.createObjectURL(result);
window.open(url, '_blank');
});
}
// Web api
[HttpGet("{id}/doc")]
public FileResult GetDoc(int id)
{
HDoc hdoc = _hDocManager.GetDoc(id);
return File(hdoc.Contents, hdoc.ContentType, hdoc.FileName);
}
解决方案
推荐阅读
- javascript - Vue 3 - 如何重命名通过 toRefs() 公开的保留关键字?
- node.js - Windows 10中的卷曲命令?
- node.js - Aws 错误无法从任何提供程序加载凭据
- python - Python 将大文本翻译成英文
- javascript - 提交表单后返回上一页&&我的js有副作用
- excel - 变量 = 工作表(=> 预期标识符)
- go - 尝试更新记录,但它插入新的
- excel - 将 Sharepoint / PowerAutomate 日期/时间转换为 Excel 序列日期/时间编号
- amazon-ec2 - ffmpeg 从 EC2 实例上的 Dropbox 转换 2tb 视频
- pandas - 从 Zip Link Pandas 读取多个文件