项目在服务器上文件上传想放到jar包所在文件夹lib的同级文件夹dist的upload文件夹中,该如何实现
@RestController
@RequestMapping("/api/bbb")
public class TimeController {
@PostMapping("/upload")
public BaseResult upload(MultipartFile file){
//获取文件名
String fileName = file.getOriginalFilename();
//获取文件后缀名
/* String suffixName = fileName.substring(fileName.lastIndexOf("."));
//重新生成文件名
fileName = UUID.randomUUID()+suffixName;*/
//指定本地文件夹存储
String filePath = ".../dist/upload/";
try {
//将图片保存到static文件夹里
file.transferTo(new File(filePath+fileName));
String tarpath = "tar -xvf"+ fileName+"-.../dist/upload";
Process process = Runtime.getRuntime().exec(tarpath);
return new BaseResult("200","success","");
} catch (Exception e) {
e.printStackTrace();
return new BaseResult("400","failed","");
}
}
}