gpt4 book ai didi

javascript - 解决C :\fakepath for file input using pure javascript or angular2

转载 作者:行者123 更新时间:2023-11-28 17:38:32 32 4
gpt4 key购买 nike

是否可以使用纯 JavaScript 或 Angular 2 获取所选文件的完整路径?我需要用户选择 Excel 文件,然后我需要将其发送到 C# WEB API Controller 方法以进行进一步处理。

现在我得到了这个:

HTML

<input type="file" id="selectedFile"  class="button-pop-up-footer1">

js

var selectedFilePath = document.getElementById("selectedFile").value;

但是当我选择位于:C:\users\owner\desktop\myfile.xls 的文件时,我得到的路径为 C:\fakepath\myfile.xls。

有人知道如何解决此问题并在不影响安全性的情况下获取文件的完整路径吗?

最佳答案

Is it possible to get the full path of the selected file using pure javascript or angular 2?

没有。这将是一个严重的安全问题。

I need the user to pick the excel file which I then need to send to c# WEB API controller method for further processing.

没关系,您不需要真正的路径。只需使用 input type="file" 并将表单发布到您的 Controller (或使用最新的 fetchXMLHttpRequest 通过 ajax 来完成 - Angular 的 http 服务应该能够胜任现代浏览器上的任务)。

关于javascript - 解决C :\fakepath for file input using pure javascript or angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48497409/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com