private String saveImageReturnPathMultipartFile multiFile) throws IllegalStateException, IOException {
String dateName = PicFileUtil.randomFileName)+multiFile.getOriginalFilename);
String path = PicFileUtil.getImgUploadPathConstants.UPLOAD_NAME); // /upload
String fileName = String.format"%s/%s", PicFileUtil.dateFolder), dateName);
String filePathName = String.format"/%s/%s", Constants.UPLOAD_NAME, fileName);
String filePath = String.format"/%s/%s", path, fileName);
File file = new FilefilePath);
if !file.getParentFile).exists)) {
file.getParentFile).mkdirs);
}
multiFile.transferTofile);
return filePathName;
}
// 上传文件
@Override
public String uploadFileMultipartFile file) {
try {
return "/ba/"+saveImageReturnPathfile);
} catch Exception e) {
e.printStackTrace);
}
return null;
}
}
文件上传地址:
public static String getImgUploadPathString folderName) {
// /home/yishang_data/project/lib/yishang_data_main.jar!/BOOT-INF/classes!/../../upload
String path = ClassUtils.getDefaultClassLoader).getResource"").getPath) + "../../../../" + folderName;
path = path.replace"file:", "");
log.info"path={}", path);
File file = new Filepath);
if ! file.exists) ) {
file.mkdirs);
}
path = getRealPathpath);
return path;
}