|
|
@ -4,6 +4,7 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.inspurcloud.oss.client.impl.OSSClientImpl; |
|
|
|
import com.inspurcloud.oss.model.CannedAccessControlList; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
@ -22,14 +23,15 @@ public class InspurStorageService extends AbstractCloudStorageService { |
|
|
|
|
|
|
|
public InspurStorageService(CloudStorageConfig config) { |
|
|
|
inspurProps = config.getInspur(); |
|
|
|
log.info("浪潮OSS参数:endPoint:{}, accessKey:{}, secretKey:{}", inspurProps.getEndPoint(), inspurProps.getAccessKey(), inspurProps.getSecretKey()); |
|
|
|
ossClient = new OSSClientImpl(inspurProps.getEndPoint(), inspurProps.getAccessKey(), inspurProps.getSecretKey()); |
|
|
|
|
|
|
|
// 设置公共读权限
|
|
|
|
//CannedAccessControlList currentAcl = ossClient.getBucketAcl(inspurProps.getBucketName());
|
|
|
|
//if (CannedAccessControlList.PublicRead != currentAcl) {
|
|
|
|
// log.info("set inspur oss acl:::::public read");
|
|
|
|
// ossClient.setBucketAcl(inspurProps.getBucketName(), CannedAccessControlList.PublicRead);
|
|
|
|
//}
|
|
|
|
CannedAccessControlList currentAcl = ossClient.getBucketAcl(inspurProps.getBucketName()); |
|
|
|
if (CannedAccessControlList.PublicRead != currentAcl) { |
|
|
|
log.info("set inspur oss acl:::::public read"); |
|
|
|
ossClient.setBucketAcl(inspurProps.getBucketName(), CannedAccessControlList.PublicRead); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -55,11 +57,13 @@ public class InspurStorageService extends AbstractCloudStorageService { |
|
|
|
@Override |
|
|
|
public String upload(InputStream inputStream, String path, String privacyType) { |
|
|
|
try { |
|
|
|
//log.info("上传参数:bucket:{}, path:{}", inspurProps.getBucketName(), path);
|
|
|
|
ossClient.putObject(inspurProps.getBucketName(), path, inputStream); |
|
|
|
|
|
|
|
// /oss统一前缀,是为了nginx做代理,识别用的。因为烟台的oss域名,需要dns,这个dns只能在服务器内网配置,政务外配置了不能用,所以需要一层代理
|
|
|
|
// "http://172.20.46.177" + "/oss" + "/oss-202212261434580001"
|
|
|
|
String url = inspurProps.getDomain() + "/oss" + "/" + path; |
|
|
|
//log.info("文件访问路径:" + url);
|
|
|
|
return url; |
|
|
|
} catch (Exception e) { |
|
|
|
String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); |
|
|
|