我在做新的Spring引导应用程序,并希望能够存储并提供图片,我想的图像将被存储在应用程序目录显示 在这里
这就是现在上传的样子:
@PostMapping("/")
@ResponseBody
public String upload(@RequestPart String title, @RequestPart MultipartFile img) throws IOException{
String imgName = img.getOriginalFilename();
Post p = new Post();
p.setTitle(title);
p.setImageName(imgName);
postService.add(p);
File upl = new File("images/" + imgName);
upl.createNewFile();
FileOutputStream fout = new FileOutputStream(upl);
fout.write(img.getBytes());
fout.close();
return "ok";
}
Run Code Online (Sandbox Code Playgroud)
这就是我想要获取图像的方式
<img th:src="@{'images/' + ${post.imageName}}"/>
Run Code Online (Sandbox Code Playgroud)
现在我得到404,当我想查看我得到的目录中的一些图像
Fatal error reading PNG image file: Not a PNG file
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能让它发挥作用?
在我的Spring Boot应用程序中,我从Thymeleaf切换到JSP,并且在我的本地计算机上正常运行,但是当我将其上传到Heroku服务器时,我得到了
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/home.jsp
它的jar打包了,如果它在本地运行而不在Heroku服务器上工作,这意味着什么?