简体   繁体   English

下载失败 - 没有文件。 反应 JS,Spring 启动

[英]Download Failed - No file. React JS, Spring Boot

I have created an application where I use React JS as frontend language to upload the file and Spring boot as backend service to save the file into the local machine directory.我创建了一个应用程序,其中我使用 React JS 作为前端语言来上传文件,Spring 引导作为后端服务将文件保存到本地机器目录中。

Eg: My path where the file I saved file in ubuntu is like /home/user/resume/resume.pdf例如:我在 ubuntu 中保存文件的路径类似于 /home/user/resume/resume.pdf

I'm trying to download the file from react js by the above path.我正在尝试通过上述路径从 react js 下载文件。 When I click it shows failed and when I check the url it appends localhost like this http://localhost:3000//home/user/resume/resume.pdf .当我单击它时显示失败,当我检查 url 时,它会像这样附加 localhost http://localhost:3000//home/user/resume/resume.Z437175BA4191210EE004E1D9374

I use this code我使用此代码

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

candidate.fileUrl = /home/user/resume/resume.pdf but it shows onclick like this http://localhost:3000/home/user/resume/resume.pdf candidate.fileUrl = /home/user/resume/resume.pdf but it shows onclick like this http://localhost:3000/home/user/resume/resume.pdf

Can anyone help me why it appends localhost before my path which results in downloading failed?谁能帮助我为什么它会在我的路径之前附加 localhost 导致下载失败?

When you put in a tag the href parameter and you precede this with "/", the browser will concatenate this compliment as PROTOCOL://SERVER:PORT/当您在标签中添加 href 参数并在其前面加上“/”时,浏览器会将这个恭维连接为 PROTOCOL://SERVER:PORT/

Well, it's how browsers works, so if you don't wanna this, you can append all the path like: "file:///home/user/resume/resume.pdf"好吧,这就是浏览器的工作方式,所以如果你不想这样,你可以 append 所有路径,如:“file:///home/user/resume/resume.pdf”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM