前言:SpringBoot在服务器内上传文件,是临时文件,在重启时候会生成另外的目录,也就意味着原来上传的图片在重启后就访问不到了。
1.图片上传
@PostMapping("/upload")
public CommonResult insertDbMsPhoto(@RequestPart("photos") MultipartFile[] photos,
@RequestParam("mid") String mid,
HttpServletRequest request){
try {
if (photos.length > 0) {
HashMap<String , String> hashMap = null;
for (MultipartFile photo : photos) {
if (!photo.isEmpty()) {
hashMap = new HashMap<>();
String originalFilename = photo.getOriginalFilename();
String sufixPhoto = originalF