WANG 5 年之前
父節點
當前提交
bcd2e2fe8c

+ 18 - 0
src/main/java/cn/com/qmth/examcloud/web/upyun/UpYunClient.java

@@ -202,6 +202,19 @@ public class UpYunClient {
 			md5 = MD5.md5Hex(file);
 		}
 
+		return writeFile(filePath, file, md5);
+	}
+
+	/**
+	 * 上传文件
+	 *
+	 * @author WANGWEI
+	 * @param filePath
+	 * @param file
+	 * @param md5
+	 * @return
+	 */
+	public UpYunPathInfo writeFile(String filePath, File file, String md5) {
 		InputStream in = null;
 		try {
 			in = new FileInputStream(file);
@@ -245,6 +258,11 @@ public class UpYunClient {
 		long s = System.currentTimeMillis();
 		try {
 			md5 = null == md5 ? "" : md5;
+
+			if (md5.equals(MD5.encrypt32(""))) {
+				throw new StatusException("100009", "empty IO stream");
+			}
+
 			String date = getDate();
 			String authorization = sign(userName, md5Password, METHOD_PUT, path, date, "", md5);
 			httpPut.addHeader(AUTHORIZATION, authorization);

+ 12 - 0
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunService.java

@@ -38,6 +38,18 @@ public interface UpyunService {
 	UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
 			boolean withMd5);
 
+	/**
+	 * 写文件
+	 *
+	 * @author WANGWEI
+	 * @param siteId
+	 * @param env
+	 * @param file
+	 * @param md5
+	 * @return
+	 */
+	UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file, String md5);
+
 	/**
 	 * 删除文件
 	 *

+ 15 - 1
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunServiceImpl.java

@@ -49,6 +49,19 @@ public class UpyunServiceImpl implements UpyunService {
 		return pathInfo;
 	}
 
+	@Override
+	public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
+			String md5) {
+		env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+
+		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
+
+		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		UpYunPathInfo pathInfo = upYunClient.writeFile(path, file, md5);
+		return pathInfo;
+	}
+
 	@Override
 	public void delete(String siteId, String filePath) {
 
@@ -59,7 +72,8 @@ public class UpyunServiceImpl implements UpyunService {
 	}
 
 	@Override
-	public UpYunHttpRequest buildUpYunHttpRequest(String siteId, UpyunPathEnvironmentInfo env, String md5) {
+	public UpYunHttpRequest buildUpYunHttpRequest(String siteId, UpyunPathEnvironmentInfo env,
+			String md5) {
 
 		env.setTimeMillis(String.valueOf(System.currentTimeMillis()));