[英]How to get a local path of file from input file in angular7?
How can I get the local path of the file from input in HTML? 如何从HTML输入中获取文件的本地路径?
By the code below I received 通过下面的代码我收到了
'C:\\fakepath\\fileTest.txt'
'C:\\ fakepath \\ fileTest.txt'
I need a local path to send to my controller in .netcore web API because I have to create a uploaded file on the backend. 我需要一个本地路径来发送到.netcore Web API中的控制器,因为我必须在后端上创建一个上载的文件。
My .ts 我的.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);
}
My .html 我的.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>
出于安全原因,您无法从用户系统获取文件的文件路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.