更新参数类型
This commit is contained in:
@ -23,16 +23,18 @@ public class ExcelUploadUtil {
|
||||
|
||||
/**
|
||||
* 上传单张图片
|
||||
* @param fileExcel
|
||||
*
|
||||
* @param fileInput
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String memoryFile(MultipartFile fileExcel) throws IOException {
|
||||
public static String memoryFile(MultipartFile fileInput, int subDirType) throws IOException {
|
||||
String subDir = subDirType == 1 ? "excel/" : "picture/";
|
||||
//String uploadPath = "http://139.199.98.175:2088/wfTaskImage/";
|
||||
// String uploadPath = "http://192.168.2.9:2088/";
|
||||
String uploadPath = "http://118.24.27.47:4096/";
|
||||
//获取原始文件名
|
||||
String originalFilename = fileExcel.getOriginalFilename();
|
||||
String originalFilename = fileInput.getOriginalFilename();
|
||||
if (originalFilename != null && !"".equals(originalFilename)) {
|
||||
//找到 . 的位置
|
||||
int index = originalFilename.lastIndexOf(".");
|
||||
@ -42,16 +44,16 @@ public class ExcelUploadUtil {
|
||||
String newName = UUID.randomUUID().toString() + suffix;
|
||||
|
||||
//将图片保存到本地/usr/etc/images/Folder
|
||||
//File file = new File("E:/shoptest/");
|
||||
File file = new File("/home/sxy/server/industrial_measurement/excel/");
|
||||
// File file = new File("/Users/liuchengqian/Desktop/DaJiang/");
|
||||
File file = new File("/home/sxy/server/industrial_measurement/" + subDir);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
//String path = "E:/shoptest/" + newName;
|
||||
String path = "/home/sxy/server/industrial_measurement/excel/" + newName;
|
||||
// String path = "/Users/liuchengqian/Desktop/DaJiang/"+newName;
|
||||
String path = "/home/sxy/server/industrial_measurement/" + subDir + newName;
|
||||
String uploadsImage = uploadPath + newName;
|
||||
//实现上传
|
||||
fileExcel.transferTo(new File(path));
|
||||
fileInput.transferTo(new File(path));
|
||||
return path;
|
||||
}
|
||||
return null;
|
||||
@ -99,27 +101,27 @@ public class ExcelUploadUtil {
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除本地或服务器储存的图片
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static String delFile(String path){
|
||||
public static String delFile(String path) {
|
||||
String resultInfo = null;
|
||||
int lastIndexOf = path.lastIndexOf("/");
|
||||
String imgPath = path.substring(lastIndexOf + 1,path.length());
|
||||
String imgPath = path.substring(lastIndexOf + 1, path.length());
|
||||
System.out.println(imgPath);
|
||||
imgPath = "/usr/local/etc/images/" + imgPath;
|
||||
// img_path = "/usr/etc/images/Folder/" + img_path;
|
||||
File file = new File(imgPath);
|
||||
if(file.exists()){
|
||||
if(file.delete()){
|
||||
if (file.exists()) {
|
||||
if (file.delete()) {
|
||||
resultInfo = "删除成功!";
|
||||
}else {
|
||||
} else {
|
||||
resultInfo = "删除失败!";
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
resultInfo = "文件不存在";
|
||||
}
|
||||
return resultInfo;
|
||||
@ -127,6 +129,7 @@ public class ExcelUploadUtil {
|
||||
|
||||
/**
|
||||
* 通过图片路径解析 ,上传保存
|
||||
*
|
||||
* @param listImgSrc
|
||||
* @return
|
||||
*/
|
||||
@ -171,17 +174,18 @@ public class ExcelUploadUtil {
|
||||
|
||||
/**
|
||||
* 删除本地文件夹图片
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
public static void deleteImage(String url){
|
||||
File file=new File(url);
|
||||
public static void deleteImage(String url) {
|
||||
File file = new File(url);
|
||||
//判断file是否是文件目录 若是返回TRUE
|
||||
if (file.isDirectory()){
|
||||
if (file.isDirectory()) {
|
||||
//name存储file文件夹中的文件名
|
||||
String[] name =file.list();
|
||||
for (int i=0; i<name.length; i++){
|
||||
String[] name = file.list();
|
||||
for (int i = 0; i < name.length; i++) {
|
||||
//此时就可得到文件夹中的文件
|
||||
File f=new File(url, name[i]);
|
||||
File f = new File(url, name[i]);
|
||||
//删除文件
|
||||
f.delete();
|
||||
}
|
||||
|
Reference in New Issue
Block a user