.
This commit is contained in:
@@ -10,7 +10,6 @@ import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/3 13:48.
|
||||
@@ -19,9 +18,9 @@ import java.nio.file.StandardCopyOption;
|
||||
public class FileService extends BaseService {
|
||||
|
||||
@Resource(name = "property.file.upload_dir")
|
||||
private String dir = "";
|
||||
private String dir = "./root/upload/";
|
||||
@Resource(name = "property.file.view_path")
|
||||
private String view = "";
|
||||
private String view = "http://127.0.0.1/upload/";
|
||||
private String format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS";
|
||||
|
||||
@RestMapping(name = "upload", comment = "文件上传")
|
||||
@@ -30,12 +29,12 @@ public class FileService extends BaseService {
|
||||
String suffix = name.substring(name.lastIndexOf("."));
|
||||
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
||||
File destFile = new File(dir + path);
|
||||
destFile.getParentFile().mkdir();
|
||||
destFile.getParentFile().mkdirs();
|
||||
if (!tmpFile.renameTo(destFile)) {
|
||||
try {
|
||||
Files.copy(tmpFile.toPath(), destFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
|
||||
Files.copy(tmpFile.toPath(), destFile.toPath());
|
||||
} finally {
|
||||
tmpFile.delete();//删除临时文件
|
||||
//tmpFile.delete();//删除临时文件
|
||||
}
|
||||
}
|
||||
RetResult result = RetResult.success();
|
||||
|
@@ -2,6 +2,7 @@ package net.tccn.bbs.servlet;
|
||||
|
||||
import net.tccn.bbs.base.BaseServlet;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
@@ -35,12 +36,12 @@ public class FileServlet extends BaseServlet {
|
||||
String name = part.getName();
|
||||
String suffix = name.substring(name.lastIndexOf("."));
|
||||
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
||||
File destFile = new File(dir + path);
|
||||
destFile.getParentFile().mkdir();
|
||||
File destFile = new File(dir + Utility.todayYYMMDD() + "/" + path);
|
||||
destFile.getParentFile().mkdirs();
|
||||
|
||||
part.save(destFile);
|
||||
|
||||
data.add(view + path);
|
||||
data.add(view + Utility.todayYYMMDD() + "/" + path);
|
||||
}
|
||||
ret.put("data", data);
|
||||
|
||||
|
Reference in New Issue
Block a user