|
|
@@ -2,6 +2,7 @@ package com.izouma.nineth.service.storage;
|
|
|
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
import com.aliyun.oss.model.ObjectMetadata;
|
|
|
+import com.izouma.nineth.config.AliyunProperties;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -17,15 +18,9 @@ import java.net.URL;
|
|
|
@Data
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-@EnableConfigurationProperties
|
|
|
-@ConfigurationProperties(prefix = "aliyun")
|
|
|
@ConditionalOnProperty(name = "storage.provider", havingValue = "aliyun")
|
|
|
public class AliStorageService implements StorageService {
|
|
|
- private String accessKeyId;
|
|
|
- private String accessKeySecret;
|
|
|
- private String ossBucketName;
|
|
|
- private String ossEndPoint;
|
|
|
- private String ossDomain;
|
|
|
+ private AliyunProperties aliyunProperties;
|
|
|
|
|
|
@Override
|
|
|
public String uploadFromInputStream(InputStream inputStream, String path) {
|
|
|
@@ -55,16 +50,17 @@ public class AliStorageService implements StorageService {
|
|
|
}
|
|
|
|
|
|
private String upload(InputStream inputStream, String path) {
|
|
|
- OSSClient client = new OSSClient(ossEndPoint, accessKeyId, accessKeySecret);
|
|
|
+ OSSClient client = new OSSClient(aliyunProperties.getOssEndPoint(), aliyunProperties.getAccessKeyId(),
|
|
|
+ aliyunProperties.getAccessKeySecret());
|
|
|
ObjectMetadata metadata = new ObjectMetadata();
|
|
|
- client.putObject(ossBucketName, path, inputStream, metadata);
|
|
|
+ client.putObject(aliyunProperties.getOssBucketName(), path, inputStream, metadata);
|
|
|
client.shutdown();
|
|
|
try {
|
|
|
inputStream.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return ossDomain + "/" + path;
|
|
|
+ return aliyunProperties.getOssDomain() + "/" + path;
|
|
|
}
|
|
|
|
|
|
}
|