SpringBoot 文件上傳至static路徑相關問題

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);

參考:http://www.qchcloud.cn/tn/article/25

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章