SpringBoot 文件上傳至static路徑相關問題
1、path 即爲文件上傳的存儲位置
例如:
Tomcat 8.5\webapps\nn\WEB-INF\classes\static\img\upfile
2、參考代碼
File path2 = new File(ResourceUtils.getURL("classpath:static").getPath().replace("%20"," ").replace('/', '\\'));
if(!path2.exists()) path2 = new File("");
//如果上傳目錄爲/static/images/upload/,則可以如下獲取:
File upload2 = new File(path2.getAbsolutePath(),"img/upfile/");
if(!upload2.exists()) upload2.mkdirs();
String path=upload2.getAbsolutePath()+"/";
FileUploadUtils.upload(path, upload);