【发布时间】:2019-08-12 22:57:40
【问题描述】:
我有在 Angular 7 Reactive Forms 中上传文件的模块(我需要响应式表单,因为我需要一起上传文件和其他一些信息)
我关注这篇文章:https://medium.com/@amcdnl/file-uploads-with-angular-reactive-forms-960fd0b34cb5
代码如下:https://pastebin.com/qsbPiJEX
onFileChange(event) {
const reader = new FileReader();
if(event.target.files && event.target.files.length) {
const [file] = event.target.files;
reader.readAsDataURL(file);
reader.onload = () => {
this.formGroup.patchValue({
file: reader.result
});
// need to run CD since file load runs outside of zone
this.cd.markForCheck();
};
}
}
据我所知,我将在 json 数据中以文本形式接收文件。 但我不知道如何将其作为文件接收或将 json 数据转换为文件。该文件可以是图像、pdf 或其他文档(excel、文档或其他格式)
我正在使用 Dotnet Core 2.2 和 Angular 7 知道如何接收文件吗?
【问题讨论】:
-
请努力以一种清晰易读的方式格式化您的问题。
标签: c# asp.net .net-core angular7 angular-reactive-forms