下载失败-没有文件。 React JS,Spring Boot

问题描述 投票:0回答:1

我创建了一个应用程序,在其中我使用React JS作为前端语言来上传文件,并使用Spring Boot作为后端服务来将文件保存到本地计算机目录中。

例如:我在ubuntu中保存文件的路径是/home/user/resume/resume.pdf,>]

我正在尝试通过上述路径从react js下载文件。当我单击它时,它显示失败,并且当我检查URL时,它会像[http://localhost:3000//home/user/resume/resume.pdf]那样附加本地主机。

我使用此代码

<a href={candidate.fileUrl} target="_blank" rel="noopener noreferrer" download>{candidate.fileName}</a>

candidate.fileUrl = /home/user/resume/resume.pdf,但它显示像[http://localhost:3000/home/user/resume/resume.pdf]这样的onclick

有人可以帮我为什么在我的路径之前附加本地主机,导致下载失败吗?

我创建了一个应用程序,在其中我使用React JS作为前端语言来上传文件,并使用Spring Boot作为后端服务来将文件保存到本地机器目录中。例如:......>

当您在标签中放入href参数,并在其前面加上“ /”时,浏览器会将这个称谓连接为PROTOCOL:// SERVER:PORT /

嗯,这是浏览器的工作方式,因此,如果您不想这样做,可以添加所有路径,例如:“ file:///home/user/resume/resume.resume.pdf”

javascript reactjs file download filepath
1个回答
0
投票

当您在标签中放入href参数,并在其前面加上“ /”时,浏览器会将这个称谓连接为PROTOCOL:// SERVER:PORT /

嗯,这是浏览器的工作方式,因此,如果您不想这样做,可以添加所有路径,例如:“ file:///home/user/resume/resume.resume.pdf”

© www.soinside.com 2019 - 2024. All rights reserved.