|
|
@ -26,10 +26,41 @@ import java.io.InputStream; |
|
|
|
*/ |
|
|
|
public class AliyunCloudStorageService extends AbstractCloudStorageService { |
|
|
|
|
|
|
|
private OSSClient internalClient = null; |
|
|
|
private OSSClient externalClient = null; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public AliyunCloudStorageService(CloudStorageConfig config){ |
|
|
|
this.config = config; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 根据隐私类型获取属性。获取client |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.01.04 13:49 |
|
|
|
*/ |
|
|
|
public OSSClient getOssClient(String privacyType) { |
|
|
|
if (PrivacyType.INTERNAL.equalsIgnoreCase(privacyType)) { |
|
|
|
if (internalClient == null){ |
|
|
|
CloudStorageConfig.AliyunCloudStorageConfigProps props = config.getAliyun().getInternal(); |
|
|
|
internalClient = new OSSClient(props.getAliyunEndPoint(), props.getAliyunAccessKeyId(), |
|
|
|
props.getAliyunAccessKeySecret()); |
|
|
|
} |
|
|
|
return internalClient; |
|
|
|
} else { |
|
|
|
if (externalClient == null) { |
|
|
|
CloudStorageConfig.AliyunCloudStorageConfigProps props = config.getAliyun().getExternal(); |
|
|
|
externalClient = new OSSClient(props.getAliyunEndPoint(), props.getAliyunAccessKeyId(), |
|
|
|
props.getAliyunAccessKeySecret()); |
|
|
|
} |
|
|
|
return externalClient; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 根据隐私类型获取属性。传递internal的时候会返回内部的,否则返回外部的,即公开的 |
|
|
|
* @return |
|
|
@ -69,11 +100,10 @@ public class AliyunCloudStorageService extends AbstractCloudStorageService { |
|
|
|
@Override |
|
|
|
public String upload(InputStream inputStream, String path, String privacyType) { |
|
|
|
CloudStorageConfig.AliyunCloudStorageConfigProps props = getPropsByprivacyType(privacyType); |
|
|
|
OSSClient client = new OSSClient(props.getAliyunEndPoint(), props.getAliyunAccessKeyId(), |
|
|
|
props.getAliyunAccessKeySecret()); |
|
|
|
OSSClient client = getOssClient(privacyType); |
|
|
|
try { |
|
|
|
client.putObject(props.getAliyunBucketName(), path, inputStream); |
|
|
|
client.shutdown(); |
|
|
|
//client.shutdown();
|
|
|
|
} catch (Exception e){ |
|
|
|
throw new RenException(ModuleErrorCode.OSS_UPLOAD_FILE_ERROR, e, ""); |
|
|
|
} |
|
|
|