|
@@ -4,6 +4,8 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.security.InvalidKeyException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.security.SignatureException;
|
|
@@ -244,7 +246,17 @@ public class UpYunClient {
|
|
|
public UpYunPathInfo writeFile(String filePath, InputStream in) {
|
|
|
return writeFile(filePath, in, "");
|
|
|
}
|
|
|
-
|
|
|
+ private String encodeFileName(String filePath) {
|
|
|
+ int inx=filePath.lastIndexOf("/");
|
|
|
+ String filename=filePath.substring(inx+1);
|
|
|
+ String head=filePath.substring(0,inx+1);
|
|
|
+ try {
|
|
|
+ return head+URLEncoder.encode(filename, "utf-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ log.error("编码失败", e);
|
|
|
+ }
|
|
|
+ return filePath;
|
|
|
+ }
|
|
|
/**
|
|
|
* 上传文件
|
|
|
*
|
|
@@ -256,6 +268,7 @@ public class UpYunClient {
|
|
|
*/
|
|
|
public UpYunPathInfo writeFile(String filePath, InputStream in, String md5) {
|
|
|
String path = formatPath(filePath);
|
|
|
+ path=encodeFileName(path);
|
|
|
String url = "https://" + API_DOMAIN + path;
|
|
|
|
|
|
HttpPut httpPut = new HttpPut(url);
|