com.aliyun.uploader.UploaderFactory Maven / Gradle / Ivy
package com.aliyun.uploader;
import com.aliyun.CommonUtils;
import com.aliyun.bean.DefaultConfigBean;
public class UploaderFactory {
public static Uploader getUploader(DefaultConfigBean config) throws Exception {
DefaultConfigBean.Oss oss = config.getOss();
if (CommonUtils.isNotEmpty(oss)) {
if (CommonUtils.isEmpty(oss.getKey()) || CommonUtils.isEmpty(oss.getBucket())) {
throw new Exception(
"You are using private OSS bucket to store package, key or bucket config can not be null.");
}
String regionId = CommonUtils.isEmpty(oss.getRegionId()) ? config.getEnv().getRegionId()
: oss.getRegionId();
if (CommonUtils.isNotEmpty(CommonUtils.logger)) {
CommonUtils.logger.info(String.format(
"Using specified OSS bucket to store package, please make sure the bucket %s:%s can be read for "
+ "public.",
regionId, oss.getBucket()));
}
String ak = CommonUtils.isEmpty(oss.getAccessKeyId()) ? config.getEnv().getAccessKeyId()
: oss.getAccessKeyId();
String sk = CommonUtils.isEmpty(oss.getAccessKeySecret()) ? config.getEnv().getAccessKeySecret()
: oss.getAccessKeySecret();
return new UserOssUploader(regionId, oss.getBucket(), oss.getKey(), ak, sk, config);
}
return new PublicOssUploader(config);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy