|
@@ -143,6 +143,7 @@ public class UpYunClient {
|
|
|
String date = getDate();
|
|
|
String authorization = null;
|
|
|
try {
|
|
|
+ md5 = null == md5 ? "" : md5;
|
|
|
authorization = sign(userName, md5Password, METHOD_PUT, path, date, "", md5);
|
|
|
} catch (Exception e) {
|
|
|
throw new StatusException("100005", "[upyun]. fail to build sign", e);
|
|
@@ -161,20 +162,29 @@ public class UpYunClient {
|
|
|
return sign;
|
|
|
}
|
|
|
|
|
|
+ public UpYunPathInfo writeFile(String filePath, File file) {
|
|
|
+ return writeFile(filePath, file, false);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 上传文件
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
* @param filePath
|
|
|
* @param file
|
|
|
+ * @param withMd5
|
|
|
* @return
|
|
|
*/
|
|
|
- public UpYunPathInfo writeFile(String filePath, File file) {
|
|
|
+ public UpYunPathInfo writeFile(String filePath, File file, boolean withMd5) {
|
|
|
+ String md5 = null;
|
|
|
+ if (withMd5) {
|
|
|
+ md5 = MD5.md5Hex(file);
|
|
|
+ }
|
|
|
|
|
|
InputStream in = null;
|
|
|
try {
|
|
|
in = new FileInputStream(file);
|
|
|
- return writeFile(filePath, in);
|
|
|
+ return writeFile(filePath, in, md5);
|
|
|
} catch (FileNotFoundException e) {
|
|
|
throw new ExamCloudRuntimeException(e);
|
|
|
} finally {
|
|
@@ -191,6 +201,19 @@ public class UpYunClient {
|
|
|
* @return
|
|
|
*/
|
|
|
public UpYunPathInfo writeFile(String filePath, InputStream in) {
|
|
|
+ return writeFile(filePath, in, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传文件
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param filePath
|
|
|
+ * @param in
|
|
|
+ * @param md5
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public UpYunPathInfo writeFile(String filePath, InputStream in, String md5) {
|
|
|
String path = formatPath(filePath);
|
|
|
String url = "https://" + API_DOMAIN + path;
|
|
|
|
|
@@ -200,12 +223,15 @@ public class UpYunClient {
|
|
|
|
|
|
long s = System.currentTimeMillis();
|
|
|
try {
|
|
|
-
|
|
|
+ md5 = null == md5 ? "" : md5;
|
|
|
String date = getDate();
|
|
|
- String authorization = sign(userName, md5Password, METHOD_PUT, path, date, "", "");
|
|
|
+ String authorization = sign(userName, md5Password, METHOD_PUT, path, date, "", md5);
|
|
|
httpPut.addHeader(AUTHORIZATION, authorization);
|
|
|
httpPut.addHeader(DATE, date);
|
|
|
httpPut.addHeader(MKDIR, "true");
|
|
|
+ if (StringUtils.isNotBlank(md5)) {
|
|
|
+ httpPut.addHeader("Content-MD5", md5);
|
|
|
+ }
|
|
|
|
|
|
httpPut.setEntity(new InputStreamEntity(in));
|
|
|
response = httpclient.execute(httpPut);
|