diff --git a/fast-boot-system/src/main/java/net/maku/storage/properties/HuaweiStorageProperties.java b/fast-boot-system/src/main/java/net/maku/storage/properties/HuaweiStorageProperties.java new file mode 100644 index 0000000..26d9ee4 --- /dev/null +++ b/fast-boot-system/src/main/java/net/maku/storage/properties/HuaweiStorageProperties.java @@ -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; +} diff --git a/fast-boot-system/src/main/java/net/maku/storage/service/HuaweiStorageService.java b/fast-boot-system/src/main/java/net/maku/storage/service/HuaweiStorageService.java new file mode 100644 index 0000000..b1e9b11 --- /dev/null +++ b/fast-boot-system/src/main/java/net/maku/storage/service/HuaweiStorageService.java @@ -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; + } + +}