新增华为云存储
This commit is contained in:
parent
f995f031b4
commit
303789289e
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user