mirror of https://github.com/elunez/eladmin
修复使用相对路径,文件上传失败问题
parent
1c19f5a614
commit
a6d128dac2
|
@ -7,6 +7,7 @@ import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -19,6 +20,7 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File工具类,扩展 hutool 工具包
|
* File工具类,扩展 hutool 工具包
|
||||||
|
*
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2018-12-27
|
* @date 2018-12-27
|
||||||
*/
|
*/
|
||||||
|
@ -44,6 +46,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MultipartFile转File
|
* MultipartFile转File
|
||||||
|
*
|
||||||
* @param multipartFile
|
* @param multipartFile
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -66,6 +69,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
|
*
|
||||||
* @param files
|
* @param files
|
||||||
*/
|
*/
|
||||||
public static void deleteFile(File... files) {
|
public static void deleteFile(File... files) {
|
||||||
|
@ -78,6 +82,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件扩展名
|
* 获取文件扩展名
|
||||||
|
*
|
||||||
* @param filename
|
* @param filename
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -93,6 +98,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java文件操作 获取不带扩展名的文件名
|
* Java文件操作 获取不带扩展名的文件名
|
||||||
|
*
|
||||||
* @param filename
|
* @param filename
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -108,6 +114,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件大小转换
|
* 文件大小转换
|
||||||
|
*
|
||||||
* @param size
|
* @param size
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -130,6 +137,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputStream 转 File
|
* inputStream 转 File
|
||||||
|
*
|
||||||
* @param ins
|
* @param ins
|
||||||
* @param name
|
* @param name
|
||||||
* @return
|
* @return
|
||||||
|
@ -166,13 +174,12 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
String nowStr = "-" + format.format(date);
|
String nowStr = "-" + format.format(date);
|
||||||
try {
|
try {
|
||||||
String fileName = name + nowStr + "." + suffix;
|
String fileName = name + nowStr + "." + suffix;
|
||||||
String path = filePath + fileName;
|
String path = filePath + File.separator + fileName;
|
||||||
File dest = new File(path);
|
File dest = new File(path).getCanonicalFile();
|
||||||
// 检测是否存在目录
|
// 检测是否存在目录
|
||||||
if (!dest.getParentFile().exists()) {
|
if (!dest.getParentFile().exists()) {
|
||||||
dest.getParentFile().mkdirs();// 新建文件夹
|
dest.getParentFile().mkdirs();// 新建文件夹
|
||||||
}
|
}
|
||||||
String d = dest.getPath();
|
|
||||||
file.transferTo(dest);// 文件写入
|
file.transferTo(dest);// 文件写入
|
||||||
return dest;
|
return dest;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -194,6 +201,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出excel
|
* 导出excel
|
||||||
|
*
|
||||||
* @param list
|
* @param list
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -236,6 +244,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
String mimeType = new MimetypesFileTypeMap().getContentType("." + type);
|
String mimeType = new MimetypesFileTypeMap().getContentType("." + type);
|
||||||
return mimeType.split("\\/")[0];
|
return mimeType.split("\\/")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkSize(long maxSize, long size) {
|
public static void checkSize(long maxSize, long size) {
|
||||||
if (size > (maxSize * 1024 * 1024)) {
|
if (size > (maxSize * 1024 * 1024)) {
|
||||||
throw new BadRequestException("文件超出规定大小");
|
throw new BadRequestException("文件超出规定大小");
|
||||||
|
|
Loading…
Reference in New Issue