|
@@ -11,6 +11,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
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.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -29,6 +31,8 @@ import cn.com.qmth.stmms.common.upyun.UpYun;
|
|
|
@RequestMapping("/file")
|
|
|
public class FileController implements InitializingBean {
|
|
|
|
|
|
+ protected static final Logger logger = LoggerFactory.getLogger(FileController.class);
|
|
|
+
|
|
|
@Value("${file.root}")
|
|
|
private String baseDir;
|
|
|
|
|
@@ -53,13 +57,16 @@ public class FileController implements InitializingBean {
|
|
|
if (StringUtils.isNotBlank(md5)) {
|
|
|
// 文件内容MD5摘要验证
|
|
|
if (!UpYun.md5(full).equals(md5)) {
|
|
|
+ logger.error("md5 check faile: " + full.getAbsolutePath());
|
|
|
response.sendError(500, "md5 check faile: " + full.getAbsolutePath());
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("write file faile: " + full.getAbsolutePath(), e);
|
|
|
response.sendError(500, "write file faile: " + full.getAbsolutePath());
|
|
|
}
|
|
|
} else {
|
|
|
+ logger.error("mkdir faile: " + parent.getAbsolutePath());
|
|
|
response.sendError(500, "mkdir faile: " + parent.getAbsolutePath());
|
|
|
}
|
|
|
}
|
|
@@ -77,10 +84,12 @@ public class FileController implements InitializingBean {
|
|
|
try {
|
|
|
IOUtils.copy(new FileInputStream(full), response.getOutputStream());
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("read file faile: " + full.getAbsolutePath(), e);
|
|
|
response.sendError(500, "read file faile: " + full.getAbsolutePath());
|
|
|
}
|
|
|
} else {
|
|
|
- response.sendError(500, "file not found: " + filePath);
|
|
|
+ logger.error("file not found: " + filePath);
|
|
|
+ response.sendError(404, "file not found: " + filePath);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -102,9 +111,11 @@ public class FileController implements InitializingBean {
|
|
|
response.addHeader(UpYun.CONTENT_MD5, UpYun.md5(full));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ logger.error("read file faile: " + full.getAbsolutePath(), e);
|
|
|
response.sendError(500, "read file faile: " + full.getAbsolutePath());
|
|
|
}
|
|
|
} else {
|
|
|
+ logger.error("file not found: " + filePath);
|
|
|
response.sendError(404, "file not found: " + filePath);
|
|
|
}
|
|
|
}
|