新增华为云存储

This commit is contained in:
阿沐 2022-08-24 11:03:42 +08:00
parent f995f031b4
commit 303789289e
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package net.maku.storage.properties;
import lombok.Data;
/**
* 华为云存储配置项
*
* @author 阿沐 babamu@126.com
*/
@Data
public class HuaweiStorageProperties {
private String endPoint;
private String accessKey;
private String secretKey;
private String bucketName;
}

View File

@ -0,0 +1,40 @@
package net.maku.storage.service;
import com.obs.services.ObsClient;
import net.maku.framework.common.exception.FastException;
import net.maku.storage.properties.StorageProperties;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
* 华为云存储
*
* @author 阿沐 babamu@126.com
*/
public class HuaweiStorageService extends StorageService {
public HuaweiStorageService(StorageProperties properties) {
this.properties = properties;
}
@Override
public String upload(byte[] data, String path) {
return upload(new ByteArrayInputStream(data), path);
}
@Override
public String upload(InputStream inputStream, String path) {
ObsClient client = new ObsClient(properties.getHuawei().getAccessKey(),
properties.getHuawei().getSecretKey(), properties.getHuawei().getEndPoint());
try {
client.putObject(properties.getHuawei().getBucketName(), path, inputStream);
client.close();
} catch (Exception e) {
throw new FastException("上传文件失败:", e);
}
return properties.getConfig().getDomain() + "/" + path;
}
}