开发项目中刚好遇见了,不知道适不适合别的项目,大家根据情况参考
1.引入的依赖
2. OBS相关配置信息
3.具体方法调用,参数要替换成对应的值:域名:domain; 桶名:bucketName; ak:accessKey; sk:securityKey;
4.OBS的一些参数生成规则方法[ObsUtil工具类中]
private static final Logger logger = LoggerFactory.getLogger(ObsUtil.class);
private static final String SIGN_SEP = "\n";
private static final String OBS_PREFIX = "x-obs-";
private static final String DEFAULT_ENCODING = "UTF-8";
private static final List<String> SUB_RESOURCES = Collections.unmodifiableList(
Arrays.asList("CDNNotifyConfiguration", "acl", "append", "attname", "backtosource", "cors", "customdomain",
"delete", "deletebucket", "directcoldaccess", "encryption", "inventory", "length", "lifecycle", "location",
"logging", "metadata", "modify", "name", "notification", "orchestration", "partNumber", "policy",
"position", "quota", "rename", "replication", "requestPayment", "response-cache-control",
"response-content-disposition", "response-content-encoding", "response-content-language",
"response-content-type", "response-expires", "restore", "select", " storageClass", "storagePolicy",
"storageinfo", "tagging", "torrent", "truncate", "uploadId", "uploads", "versionId", "versioning",
"versions", "website", "x-image-process", "x-image-save-bucket", "x-image-save-object",
"x-obs-security-token"));
public static String urlEncode(String input) {
try {
return URLEncoder.encode(input, DEFAULT_ENCODING).replaceAll("%7E", "~") // for browser
.replaceAll("%2F", "/"