Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以仅从尝试将内容上传到服务器的用户读取文件名/路径?
例如,当用户在实际上传到服务器之前选择了一些要上传的文件时,我想读取文件信息。
fs.readdir可用于读取目录的内容,但用户选择的文件呢?
你不能。浏览器只允许在您上传文件时发送文件名。这样做意味着将您的目录结构暴露给服务器。(非常糟糕的主意)
这是一个安全标准和一个好的做法,不要放弃您发送到服务器的文件的完整位置。应该有单独的路径来处理服务器和客户端上的文件。