html - 如何从angular7中的输入文件获取文件的本地路径?
问题描述
如何从 HTML 中的输入中获取文件的本地路径?
通过下面的代码我收到
'C:\fakepath\fileTest.txt'
我需要一个本地路径来发送到 .netcore Web API 中的控制器,因为我必须在后端创建一个上传的文件。
我的.ts
fileChanged(e) {
this.file = e.target.files[0];
console.log('name of file' + this.file.name); // name of file
console.log('path of file' + e.target.value); // path of file
}
uploadDocument(file) {
let fileReader = new FileReader();
fileReader.onload = (e) => {
console.log(fileReader.result);
};
fileReader.readAsText(file);
console.log('sadasdas' + file);
}
我的.html
<div class="col-md-6">
<p class="my-0">Attachements</p>
<input type="file" (change)="fileChanged($event)" class="btn btn-secondary" appBootstrapErrors [formControlName]="formControlNames.ATTACHEMENTS">
</div>
解决方案
出于安全原因,您无法从用户系统获取文件的文件路径。
推荐阅读
- ssl - 多层系统中 TLS 协议的传播方式
- makefile - GNU Make 只执行 10 条规则
- mesos - 我们是否必须在每个节点上编译 Mesos?
- c++ - Qt 使用 exec() 循环测试 QMessageBoxes(或通用 QDialog)
- jquery - 从html中的表单提交中排除隐藏元素
- android - 发布带有风味的 android 库
- amazon-web-services - 如何为自动缩放组中动态创建的资源设置 cloudwatch 指标
- java - 如何使用 java 从网站获取文本内容?
- java - 分组时将分页结果的 MongoDB 聚合添加到 Java 代码中添加其他字段
- python - Pytesseract:“TesseractNotFound 错误:tesseract 未安装或不在您的路径中”,我该如何解决?