Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
593620998f | ||
|
|
dbb6bb1f17 |
@@ -13,6 +13,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -279,9 +280,12 @@ public static BufferedImage cutImgBuf(InputStream img,Positions p,int x,int y,in
|
||||
* @return 图片路径(相对)
|
||||
*/
|
||||
public static String putImg(ServletContext servletContext,MultipartFile file,String path,String towhere) {
|
||||
int maxSize = 1024*1024*2; //上传最大为2MB
|
||||
if (file==null||file.getSize()>maxSize) {
|
||||
return "图片最大上传2MB";
|
||||
long maxSize = Utils.getNum(ReadTxt.getSetting(null, "setting.ini", "imgsize", "10")) * 1048576; //上传最大 MB
|
||||
if (file==null) {
|
||||
return "";
|
||||
}
|
||||
if (file.getSize()>maxSize) {
|
||||
return "文件最大上传"+(maxSize/1048576)+"MB";
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +301,6 @@ public static String putImg(ServletContext servletContext,MultipartFile file,Str
|
||||
path = "D:/"+(lpath.replaceAll("D:/", "").replaceAll("D://", "").replaceAll("D:", "").replaceAll("c:", ""));//图片存储在C盘下的路径
|
||||
else{
|
||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||
@@ -372,10 +375,14 @@ public static String putImg(ServletContext servletContext,MultipartFile file,Str
|
||||
* @return 图片路径(相对)
|
||||
*/
|
||||
public static String putImgAsName(ServletContext servletContext,MultipartFile file,String path,String filename,String towhere) {
|
||||
int maxSize = 1024*1024*2; //上传最大为2MB
|
||||
if (file==null||file.getSize()>maxSize) {
|
||||
return "图片最大上传2MB";
|
||||
long maxSize = Utils.getNum(ReadTxt.getSetting(null, "setting.ini", "imgsize", "10")) * 1048576; //上传最大 MB
|
||||
if (file==null) {
|
||||
return "";
|
||||
}
|
||||
if (file.getSize()>maxSize) {
|
||||
return "文件最大上传"+(maxSize/1048576)+"MB";
|
||||
}
|
||||
|
||||
File targetFile=null;
|
||||
String rid="";
|
||||
String realurl="";//返回存储路径
|
||||
@@ -387,7 +394,6 @@ public static String putImgAsName(ServletContext servletContext,MultipartFile fi
|
||||
path = "D:/"+(lpath.replaceAll("D:/", "").replaceAll("D://", "").replaceAll("D:", "").replaceAll("c:", ""));//图片存储在C盘下的路径
|
||||
else{
|
||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||
@@ -466,13 +472,14 @@ public static String putImgAsName(ServletContext servletContext,MultipartFile fi
|
||||
* @return 图片路径(相对)
|
||||
*/
|
||||
public static String putVideo(ServletContext servletContext,MultipartFile file,String path,String towhere) {
|
||||
int maxSize = 1024*1024*10; //上传最大为2MB
|
||||
long maxSize = Utils.getNum(ReadTxt.getSetting(null, "setting.ini", "videosize", "50")) * 1048576; //上传最大 MB
|
||||
if (file==null) {
|
||||
return "";
|
||||
}
|
||||
if (file.getSize()>maxSize) {
|
||||
return "视频最大上传10MB";
|
||||
return "文件最大上传"+(maxSize/1048576)+"MB";
|
||||
}
|
||||
|
||||
File targetFile=null;
|
||||
String rid="";
|
||||
String realurl="";//返回存储路径
|
||||
@@ -485,7 +492,6 @@ public static String putVideo(ServletContext servletContext,MultipartFile file,S
|
||||
else{
|
||||
|
||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||
@@ -565,12 +571,12 @@ public static String putVideo(ServletContext servletContext,MultipartFile file,S
|
||||
* @return 图片路径(相对)
|
||||
*/
|
||||
public static String putFile(ServletContext servletContext,MultipartFile file,String filename,String path,String towhere) {
|
||||
int maxSize = 1024*1024*10; //上传最大为2MB
|
||||
long maxSize = Utils.getNum(ReadTxt.getSetting(null, "setting.ini", "filesize", "50")) * 1048576; //上传最大 MB
|
||||
if (file==null) {
|
||||
return "";
|
||||
}
|
||||
if (file.getSize()>maxSize) {
|
||||
return "文件最大上传20MB";
|
||||
return "error:文件最大上传"+(maxSize/1048576)+"MB";
|
||||
}
|
||||
File targetFile=null;
|
||||
String rid="";
|
||||
@@ -583,7 +589,6 @@ public static String putFile(ServletContext servletContext,MultipartFile file,St
|
||||
path = "D:/"+(lpath.replaceAll("D:/", "").replaceAll("D://", "").replaceAll("D:", "").replaceAll("c:", ""));//图片存储在C盘下的路径
|
||||
else{
|
||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||
@@ -626,7 +631,7 @@ public static String putFile(ServletContext servletContext,MultipartFile file,St
|
||||
//System.out.println("图片上传成功 \nUrl:"+realurl);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "系统异常,视频上传失败";
|
||||
return "error:系统异常,视频上传失败";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -722,7 +727,6 @@ public static String writeFile(ServletContext servletContext, String path,
|
||||
else path1 = path;
|
||||
} else {
|
||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||
@@ -788,7 +792,7 @@ public static void delfile(ServletContext servletContext, String path) {
|
||||
path=rs.get(0).get("realurl")+"";
|
||||
path1=rs.get(0).get("realurl")+"";
|
||||
}
|
||||
} else path1 = servletContext.getRealPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
File file1 = new File(path1);
|
||||
@@ -835,7 +839,7 @@ public static void delFileForStr(ServletContext servletContext, String str) {
|
||||
oldpath=rs.get(0).get("realurl")+"";
|
||||
path1=rs.get(0).get("realurl")+"";
|
||||
}
|
||||
} else path1 = servletContext.getRealPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
File file1 = new File(path1);
|
||||
@@ -951,13 +955,19 @@ public static MultipartFile getMultipartFile(File file) {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static ResponseEntity<FileSystemResource> returnFile(File file) {
|
||||
public static ResponseEntity<FileSystemResource> returnFile(File file, String name) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if(name!=null&&name.length()>0)
|
||||
name = new String(name.getBytes("UTF-8"),"ISO-8859-1");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
headers.add("Content-Disposition", "attachment; filename=" + file.getName());
|
||||
headers.add("Content-Disposition", "attachment; filename=" + (name!=null&&name.length()>0?name:file.getName()));
|
||||
headers.add("Pragma", "no-cache");
|
||||
headers.add("Expires", "0");
|
||||
headers.add("Last-Modified", new Date().toString());
|
||||
|
||||
Reference in New Issue
Block a user