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

你可能感兴趣的:(SpringBoot)