下载失败 - 无文件.React JS,Spring Boot



我创建了一个应用程序,其中我使用 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但它像这样显示 onclick http://localhost:3000/home/user/resume/resume.pdf

谁能帮我为什么它会在我的路径之前附加本地主机,从而导致下载失败?

当您输入 href 参数标签并在前面加上"/"时,浏览器会将此赞美连接为 PROTOCOL://SERVER:PORT/

好吧,这就是浏览器的工作方式,所以如果你不想这样做,你可以附加所有路径,比如:"file:///home/user/resume/resume.pdf">

最新更新