如何在 reactjs 中上传文件并将路径保存到 JSON 服务器中的文件?

How can I upload a file in a reactjs and save the path to the file in the JSON server?

这里应该怎么做才能得到路径 const [file, setFile] = useState("");

function handleUpload(e) {
     setFile(e.target.files[0]);
//what should i do here to get the path
}
 <Button variant="contained" component="label" >Upload File <input type="file" hidden  webkitdirectory onChange={(e)=>handleUpload(e)}/></Button>

出于安全原因,浏览器不允许这样做,即 JavaScript 在浏览器中无法访问文件系统,但是使用 HTML5 文件 API,只有 Firefox 提供了 mozFullPath 属性,但如果您尝试获取它的值 returns 一个空字符串:

可能 duplicate