提交 b0934c5d 编写于 作者: O o2sword

增加附件阿里云存储OSS支持

上级 c3634246
......@@ -252,6 +252,11 @@ public abstract class StorageObject extends SliceJpaObject {
+ URLEncoder.encode(mapping.getPassword(), DefaultCharset.name) + "@" + mapping.getHost() + ":"
+ mapping.getPort();
break;
case ali:
prefix = "ali://" + URLEncoder.encode(mapping.getUsername(), DefaultCharset.name) + ":"
+ URLEncoder.encode(mapping.getPassword(), DefaultCharset.name) + "@" + mapping.getHost() + "/"
+ mapping.getName();
break;
case file:
prefix = "file://";
break;
......@@ -261,7 +266,18 @@ public abstract class StorageObject extends SliceJpaObject {
default:
break;
}
return prefix + (StringUtils.isEmpty(mapping.getPrefix()) ? "" : ("/" + mapping.getPrefix()));
String mappingPrefix = "";
if(StringUtils.isNotBlank(mapping.getPrefix())){
if(mapping.getPrefix().startsWith("/")){
mappingPrefix = mapping.getPrefix();
}else{
mappingPrefix = "/" + mapping.getPrefix();
}
if(mappingPrefix.endsWith("/")) {
mappingPrefix = mappingPrefix.substring(0, mappingPrefix.length()-1);
}
}
return prefix + mappingPrefix;
}
private FileSystemOptions getOptions(StorageMapping mapping) throws Exception {
......@@ -356,7 +372,8 @@ public abstract class StorageObject extends SliceJpaObject {
length = IOUtils.copyLarge(inputStream, output);
this.setLength(length);
if ((!Objects.equals(StorageProtocol.webdav, mapping.getProtocol()))
&& (!Objects.equals(StorageProtocol.sftp, mapping.getProtocol()))) {
&& (!Objects.equals(StorageProtocol.sftp, mapping.getProtocol()))
&& (!Objects.equals(StorageProtocol.ali, mapping.getProtocol()))) {
/* webdav关闭会试图去关闭commons.httpClient */
manager.closeFileSystem(fo.getFileSystem());
}
......
package com.x.base.core.entity;
public enum StorageProtocol {
ftp, ftps, webdav, cifs, file, sftp, hdfs;
ftp, ftps, webdav, cifs, file, sftp, hdfs, ali;
public static final int length = JpaObject.length_16B;
}
......@@ -7,10 +7,14 @@ import com.x.base.core.entity.StorageProtocol;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.tools.Crypto;
/**
* 第三方附件存储配置
* @author sword
*/
public class ExternalStorageSource extends ConfigObject {
private static final long serialVersionUID = 5926439816241094368L;
// 无需保存
private transient String _password;
......@@ -43,13 +47,13 @@ public class ExternalStorageSource extends ConfigObject {
public static final String DEFAULT_NAME = "251";
public static final Boolean DEFAULT_DEEPPATH = false;
@FieldDescribe("协议,可选值ftp,webdav...")
@FieldDescribe("协议,可选值ftp、sftp、webdav、file、hdfs、ali")
private StorageProtocol protocol;
@FieldDescribe("登录用户名.")
private String username;
@FieldDescribe("登录密码.")
private String password;
@FieldDescribe("主机地址.")
@FieldDescribe("主机地址或阿里云endpoint.")
private String host;
@FieldDescribe("端口.")
private Integer port;
......@@ -59,7 +63,7 @@ public class ExternalStorageSource extends ConfigObject {
private Boolean enable;
@FieldDescribe("设置权重.")
private Integer weight;
@FieldDescribe("存储节点名,对应存储名称,谨慎修改.")
@FieldDescribe("存储节点名,对应存储名称,阿里云为bucket(桶)名称.")
private String name;
@FieldDescribe("是否使用更深的路径.")
private Boolean deepPath;
......@@ -107,4 +111,4 @@ public class ExternalStorageSource extends ConfigObject {
return BooleanUtils.isTrue(this.deepPath);
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册