Commit a09b3090 by 黎配弘

尝试修复路径遍历

parent 0442250b
......@@ -17,7 +17,7 @@ import java.io.OutputStream;
public class FileUtil {
//写到相应路径
public static boolean makefile(String path, MultipartFile file,String filename){
/*public static boolean makefile(String path, MultipartFile file,String filename){
File dir = new File(path);
if (!dir.exists()) {
......@@ -40,9 +40,9 @@ public class FileUtil {
}
}
return true;
}
}*/
public static boolean makefile1(String path, MultipartFile file,String filename){
/*public static boolean makefile1(String path, MultipartFile file,String filename){
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
......@@ -62,5 +62,5 @@ public class FileUtil {
}
}
return true;
}
}*/
}
......@@ -29,6 +29,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -244,8 +247,18 @@ public class SchoolManagementController extends BaseController {
@Permission(menuname = "上传二维码", value = "qrcodeUpload", method = RequestMethod.POST)
public ResponseData<String>xiaotuUpload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "id",required = false) String id) {
String backgroundpath= FilePath.BACKGROUNDIMG.getValue()+"/"+DEFAULTPATH;
boolean makefile = FileUtil.makefile(backgroundpath, file,id+FILENAME);
String backgroundpath = FilePath.BACKGROUNDIMG.getValue() + "/" + DEFAULTPATH;
File dir = new File(backgroundpath);
if (!dir.exists()) {
dir.mkdirs();
}
File savePath = new File(backgroundpath, id + FILENAME);
OutputStream os = null;
try {
os = new FileOutputStream(savePath);
os.write(file.getBytes());
os.flush();
Wrapper<School> wrapper = new EntityWrapper<>();
wrapper.eq("id",id);
Map<String, Object> map = new HashMap<>();
......@@ -255,6 +268,16 @@ public class SchoolManagementController extends BaseController {
return ResponseData.error("上传失败!");
}
return ResponseData.success("上传成功" );
} catch (Exception e) {
log.error("上传文件失败:" + e.getMessage(), e);
return ResponseData.error("上传失败" + e.getMessage());
} finally {
if (os != null) {
try{
os.close();
}catch(Exception e) {}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment