| | |
| | | import java.nio.charset.StandardCharsets;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import org.apache.commons.io.FilenameUtils;
|
| | | import org.apache.commons.io.IOUtils;
|
| | | import org.apache.commons.lang3.ArrayUtils;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | |
| | | // 路径为文件且不为空则进行删除
|
| | | if (file.isFile() && file.exists())
|
| | | {
|
| | | file.delete();
|
| | | flag = true;
|
| | | flag = file.delete();
|
| | | }
|
| | | return flag;
|
| | | }
|
| | |
| | | *
|
| | | * @param response 响应对象
|
| | | * @param realFileName 真实文件名
|
| | | * @return
|
| | | */
|
| | | public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException
|
| | | {
|
| | |
| | | .append("utf-8''")
|
| | | .append(percentEncodedFileName);
|
| | |
|
| | | response.addHeader("Access-Control-Allow-Origin", "*");
|
| | | response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
|
| | | response.setHeader("Content-disposition", contentDispositionValue.toString());
|
| | | response.setHeader("download-filename", percentEncodedFileName);
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 获取名称
|
| | | * 获取文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi.png
|
| | | *
|
| | | * @param fileName 路径名称
|
| | | * @return 没有文件路径的名称
|
| | |
| | | int index = Math.max(lastUnixPos, lastWindowsPos);
|
| | | return fileName.substring(index + 1);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取不带后缀文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi
|
| | | * |
| | | * @param fileName 路径名称
|
| | | * @return 没有文件路径和后缀的名称
|
| | | */
|
| | | public static String getNameNotSuffix(String fileName)
|
| | | {
|
| | | if (fileName == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | String baseName = FilenameUtils.getBaseName(fileName);
|
| | | return baseName;
|
| | | }
|
| | | }
|