|
@@ -10,6 +10,7 @@ import java.util.Map;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.ksyun.ks3.dto.PostObjectFormFields;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.util.IOUtils;
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
@@ -144,6 +145,40 @@ public class KS3StoragePlugin implements StoragePlugin, InitializingBean, Dispos
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public String postObjectSimple(Map<String, String> postData,List<String> unknowValueField) {
|
|
|
+ // yourEndpoint填写Bucket所在地域对应的Endpoint。以中国(北京)为例,Endpoint填写为ks3-cn-beijing.ksyuncs.com。如果使用自定义域名,设置endpoint为自定义域名,同时设置domainMode为true
|
|
|
+ //String endpoint = "yourEndpoint";
|
|
|
+ // 金山云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用子账号账号进行 API 访问或日常运维,请登录 https://uc.console.ksyun.com/pro/iam/#/user/list 创建子账号。
|
|
|
+ //String accessKeyId = "yourAccessKeyId";
|
|
|
+ //String accessKeySecret = "yourAccessKeySecret";
|
|
|
+ // 创建Ks3ClientConfig 实例。
|
|
|
+ Ks3ClientConfig config = new Ks3ClientConfig();
|
|
|
+ // 设置域名
|
|
|
+ config.setEndpoint(endpoint);
|
|
|
+ // 创建Ks3Client实例
|
|
|
+ Ks3 client = new Ks3Client(accessKeyId, accessKeySecret, config);
|
|
|
+ /**
|
|
|
+ * 需要用户在postData和unknowValueField中提供所有的除KSSAccessKeyId, signature, file, policy外的所有表单项。否则用生成的签名上传会返回403</br>
|
|
|
+ * 对于用户可以确定表单值的放在 postData中,对于用户无法确定表单值的放在unknownValueField中(比如有的上传控件会添加一些表单项,但表单项的值可能是随机的)</br>
|
|
|
+ */
|
|
|
+ //Map<String, String> postData = new HashMap<String, String>();
|
|
|
+ // 如果使用js sdk上传的时候设置了ACL,请提供以下一行,且值要与SDK中一致,否则删除下面一行代码
|
|
|
+ //postData.put("acl","public-read");
|
|
|
+ // 提供js sdk中的key值
|
|
|
+ //postData.put("key","20150115/中文/${filename}");
|
|
|
+ // 设置无法确定的表单值
|
|
|
+ //List<String> unknowValueField = new ArrayList<String>();
|
|
|
+ // js sdk上传的时候会自动加上一个name的表单项,所以下面需要加上这样的代码。
|
|
|
+ unknowValueField.add("name");
|
|
|
+ // 如果计算签名时提供的key里不包含${filename}占位符,第二个参数传一个空字符串。
|
|
|
+ String postDataKey = postData.get("key");
|
|
|
+ if (StringUtils.isNotBlank(postDataKey)){
|
|
|
+
|
|
|
+ }
|
|
|
+ PostObjectFormFields fields = client.postObject(bucketName, "<要上传的文件名称,不包含路径信息>", postData, unknowValueField);
|
|
|
+ return JSON.toJSONString(fields);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void destroy() throws Exception {
|
|
|
}
|