我目前设置了一个 Node 服务器,能够将文件上传到服务器上。我希望用户能够单击链接打开文件目录以查看已上传到服务器的所有文件。我想知道这是否可行。
<a href="localhost:80/testexample/uploads"> UPLOADS DIRECTORY</a>
<a href="localhost/testexample/uploads"> UPLOADS DIRECTORY</a>
<a href="http://localhost/testexample/uploads"> UPLOADS DIRECTORY</a>
<a href="http://localhost/uploads"> UPLOADS DIRECTORY</a><br>
我尝试过但没有成功的示例代码。是否可以执行我想要执行的功能?
我尝试通过将文件目录路径放在“a”标记内来在本地执行此操作,它会显示整个目录。我想对服务器做类似的事情。任何帮助将不胜感激!
最佳答案
一般情况下你可以这样做
<a href="/testexample/uploads"> UPLOADS DIRECTORY</a>
当路由命中时,服务器会返回一个页面。
router.get('/testexample/uploads', (req, res, next) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
}
此页面可以包含您的图像,如下所示:
<img src="/path-to-img-from-this-file"/>
<img src="/path-to-img-from-this-file"/>
<img src="/path-to-img-from-this-file"/>
关于html - 如何链接到 Node 内的文件目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55925888/