|
@@ -11,6 +11,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -30,6 +32,8 @@ import cn.com.qmth.stmms.common.upyun.UpYun;
|
|
@RequestMapping("/file")
|
|
@RequestMapping("/file")
|
|
public class FileController implements InitializingBean {
|
|
public class FileController implements InitializingBean {
|
|
|
|
|
|
|
|
+ protected static final Logger log = LoggerFactory.getLogger(FileController.class);
|
|
|
|
+
|
|
@Value("${file.root}")
|
|
@Value("${file.root}")
|
|
private String baseDir;
|
|
private String baseDir;
|
|
|
|
|
|
@@ -38,7 +42,7 @@ public class FileController implements InitializingBean {
|
|
@RequestMapping(value = "/**", method = { RequestMethod.PUT, RequestMethod.POST })
|
|
@RequestMapping(value = "/**", method = { RequestMethod.PUT, RequestMethod.POST })
|
|
public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
if (enable == false) {
|
|
if (enable == false) {
|
|
- response.sendError(500, "file api disable");
|
|
|
|
|
|
+ response.sendError(401, "file api disable");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -54,13 +58,16 @@ public class FileController implements InitializingBean {
|
|
if (StringUtils.isNotBlank(md5)) {
|
|
if (StringUtils.isNotBlank(md5)) {
|
|
// 文件内容MD5摘要验证
|
|
// 文件内容MD5摘要验证
|
|
if (!UpYun.md5(full).equals(md5)) {
|
|
if (!UpYun.md5(full).equals(md5)) {
|
|
|
|
+ log.error("md5 check faile: " + full.getAbsolutePath());
|
|
response.sendError(500, "md5 check faile: " + full.getAbsolutePath());
|
|
response.sendError(500, "md5 check faile: " + full.getAbsolutePath());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
+ log.error("write file faile: " + full.getAbsolutePath(), e);
|
|
response.sendError(500, "write file faile: " + full.getAbsolutePath());
|
|
response.sendError(500, "write file faile: " + full.getAbsolutePath());
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
|
|
+ log.error("mkdir faile: " + parent.getAbsolutePath());
|
|
response.sendError(500, "mkdir faile: " + parent.getAbsolutePath());
|
|
response.sendError(500, "mkdir faile: " + parent.getAbsolutePath());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -68,7 +75,7 @@ public class FileController implements InitializingBean {
|
|
@RequestMapping(value = "/**", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/**", method = RequestMethod.GET)
|
|
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
if (enable == false) {
|
|
if (enable == false) {
|
|
- response.sendError(500, "file api disable");
|
|
|
|
|
|
+ response.sendError(401, "file api disable");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -78,17 +85,18 @@ public class FileController implements InitializingBean {
|
|
try {
|
|
try {
|
|
FileCopyUtils.copy(new FileInputStream(full), response.getOutputStream());
|
|
FileCopyUtils.copy(new FileInputStream(full), response.getOutputStream());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
+ log.error("read file faile: " + full.getAbsolutePath(), e);
|
|
response.sendError(500, "read file faile: " + full.getAbsolutePath());
|
|
response.sendError(500, "read file faile: " + full.getAbsolutePath());
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- response.sendError(500, "file not found: " + filePath);
|
|
|
|
|
|
+ response.sendError(404, "file not found: " + filePath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/**", method = RequestMethod.HEAD)
|
|
@RequestMapping(value = "/**", method = RequestMethod.HEAD)
|
|
public void info(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
public void info(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
if (enable == false) {
|
|
if (enable == false) {
|
|
- response.sendError(500, "file api disable");
|
|
|
|
|
|
+ response.sendError(401, "file api disable");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -103,6 +111,7 @@ public class FileController implements InitializingBean {
|
|
response.addHeader(UpYun.CONTENT_MD5, UpYun.md5(full));
|
|
response.addHeader(UpYun.CONTENT_MD5, UpYun.md5(full));
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
+ log.error("read file faile: " + full.getAbsolutePath(), e);
|
|
response.sendError(500, "read file faile: " + full.getAbsolutePath());
|
|
response.sendError(500, "read file faile: " + full.getAbsolutePath());
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|