我正在构建一个spring-boot应用程序,在这个应用程序中,用户必须输入一个文件(图像、文本或他想要的任何东西),这个文件最终将通过邮件自动发送给我。在我的html模板中,我使用这个来请求输出;
<div class="custom-file">
<input type="file" class="custom-file-input"
name="6?-BBtn9E@=G8Yua" id="6?-BBtn9E@=G8Yua"> <label
class="custom-file-label" for="6?-BBtn9E@=G8Yua">Select file</label>
</div>
如你所见,我正在使用引导。
在我的spring boot控制器中,我是这样得到这个参数的;
@RequestParam(name = "6?-BBtn9E@=G8Yua", required = false) File userFile
然后邮件将定期发送(我之前测试过邮件发送是否有效,当时我还没有这个文件输入问题),因此我将向您展示附件;
HtmlEmail email = new HtmlEmail();
email.attach(userFile);
email.send();
然而,当我提交时,我在控制台中得到这个ioexception;
java.io.IOException: "/Users/username/Eclipse-Workspace/Website/file.txt" does not exist
我找到了一个名为file.txt的文件,因为我在mac电脑上运行这个文件,所以路径是/users/{myusername}/{eclipse workspace}/{spring boot project/{file name}。我想要的是springboot从项目中搜索出来,而不仅仅是在项目内部。
为什么要这么做?感谢阅读!
1条答案
按热度按时间2j4z5cfb1#
当您希望spring查看所需的项目文件夹外部时:
"file:/Users/username/Eclipse-Workspace/Website/file.txt"
.