c# - 如何使用 Angular 7 将存储在 SQL Server 数据库中的文件作为 varbinary 类型下载?
问题描述
我正在尝试使用 typscipt angula 7 将存储在 sql server 数据库表中的文件作为 vrabinary 类型下载
我能够从数据库中获取具有 fileName 和 fileContent 作为 varbinay 类型的对象(res)
public download = (fileId) => {
this.fileService.getFilediaById(fileId)
.subscribe(res => {
this.isLoading = false;
if (res != null)
{
const data = res.fileContent; // of type varbinary
const filename = res.fileName;
const blob = new Blob([data], { type: 'application/pdf' });
this.fileUrl = this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob));
}
},
error => {
console.log(error);
});
}
<a [href]="fileUrl" [download]="fileName" mat-menu-item (click)="download(fileId)">Download</a>
但文件为空并出现错误“失败 - 无文件”
谢谢
解决方案
推荐阅读
- javascript - 使滑块气泡跟上左手柄
- tensorflow - MASK-RCNN 的标记数据集:只有观察良好的对象?
- linq - 在超过 14 个条目的列表中使用包含时,mobileservicesynctable pullasync 失败
- racket - 合同可以匹配吗?
- python - 为什么枕头将图像加载为矩形而不是圆形?
- javascript - JSON.stringify 带有键的对象,子对象中没有引号
- linux - 在 Linux 上确定自进程启动以来的时间
- django - django csv import-export 的外键不匹配错误
- html - 在 Bootstrap 网格中安排响应式图像视图
- android - 如何更改 Termux 中的默认启动文件夹?