mirror of https://github.com/halo-dev/halo
Fixed ali oss upload error.
parent
0c8955dfcf
commit
8e9f4dff06
|
@ -46,6 +46,7 @@ public class AliYunFileHandler implements FileHandler {
|
||||||
String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY).toString();
|
String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY).toString();
|
||||||
String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET).toString();
|
String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET).toString();
|
||||||
String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME).toString();
|
String ossBucketName = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_BUCKET_NAME).toString();
|
||||||
|
String ossStyleRule = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_STYLE_RULE).toString();
|
||||||
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
|
@ -78,7 +79,7 @@ public class AliYunFileHandler implements FileHandler {
|
||||||
BufferedImage image = ImageIO.read(file.getInputStream());
|
BufferedImage image = ImageIO.read(file.getInputStream());
|
||||||
uploadResult.setWidth(image.getWidth());
|
uploadResult.setWidth(image.getWidth());
|
||||||
uploadResult.setHeight(image.getHeight());
|
uploadResult.setHeight(image.getHeight());
|
||||||
uploadResult.setThumbPath(filePath);
|
uploadResult.setThumbPath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploadResult;
|
return uploadResult;
|
||||||
|
|
|
@ -53,11 +53,11 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
|
|
||||||
// Get all config
|
// Get all config
|
||||||
Zone zone = optionService.getQnYunZone();
|
Zone zone = optionService.getQnYunZone();
|
||||||
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString();
|
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_ACCESS_KEY).toString();
|
||||||
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString();
|
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_SECRET_KEY).toString();
|
||||||
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString();
|
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_BUCKET).toString();
|
||||||
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.DOMAIN).toString();
|
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_DOMAIN).toString();
|
||||||
String smallUrl = optionService.getByPropertyOrDefault(QnYunProperties.SMALL_URL, String.class, "");
|
String styleRule = optionService.getByPropertyOrDefault(QnYunProperties.OSS_STYLE_RULE, String.class, "");
|
||||||
|
|
||||||
// Create configuration
|
// Create configuration
|
||||||
Configuration configuration = new Configuration(zone);
|
Configuration configuration = new Configuration(zone);
|
||||||
|
@ -109,9 +109,10 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
result.setWidth(putSet.getWidth());
|
result.setWidth(putSet.getWidth());
|
||||||
result.setHeight(putSet.getHeight());
|
result.setHeight(putSet.getHeight());
|
||||||
result.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
result.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
||||||
|
result.setSize(file.getSize());
|
||||||
|
|
||||||
if (isImageType(result.getMediaType())) {
|
if (isImageType(result.getMediaType())) {
|
||||||
result.setThumbPath(StringUtils.isBlank(smallUrl) ? filePath : filePath + smallUrl);
|
result.setThumbPath(StringUtils.isBlank(styleRule) ? filePath : filePath + styleRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -130,9 +131,9 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
|
|
||||||
// Get all config
|
// Get all config
|
||||||
Zone zone = optionService.getQnYunZone();
|
Zone zone = optionService.getQnYunZone();
|
||||||
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString();
|
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_ACCESS_KEY).toString();
|
||||||
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString();
|
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_SECRET_KEY).toString();
|
||||||
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString();
|
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_BUCKET).toString();
|
||||||
|
|
||||||
// Create configuration
|
// Create configuration
|
||||||
Configuration configuration = new Configuration(zone);
|
Configuration configuration = new Configuration(zone);
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString();
|
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString();
|
||||||
String ossDomain = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_DOMAIN).toString();
|
String ossDomain = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_DOMAIN).toString();
|
||||||
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
|
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
|
||||||
// small url can be null
|
// style rule can be null
|
||||||
String ossSmallUrl = optionService.getByPropertyOrDefault(UpYunProperties.OSS_SMALL_URL, String.class, "");
|
String ossStyleRule = optionService.getByPropertyOrDefault(UpYunProperties.OSS_STYLE_RULE, String.class, "");
|
||||||
|
|
||||||
// Create up yun
|
// Create up yun
|
||||||
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
|
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
|
||||||
|
@ -86,7 +86,7 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
BufferedImage image = ImageIO.read(file.getInputStream());
|
BufferedImage image = ImageIO.read(file.getInputStream());
|
||||||
uploadResult.setWidth(image.getWidth());
|
uploadResult.setWidth(image.getWidth());
|
||||||
uploadResult.setHeight(image.getHeight());
|
uploadResult.setHeight(image.getHeight());
|
||||||
uploadResult.setThumbPath(StringUtils.isBlank(ossSmallUrl) ? filePath : filePath + ossSmallUrl);
|
uploadResult.setThumbPath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploadResult;
|
return uploadResult;
|
||||||
|
|
|
@ -26,7 +26,12 @@ public enum AliYunProperties implements PropertyEnum {
|
||||||
/**
|
/**
|
||||||
* Aliyun oss access secret.
|
* Aliyun oss access secret.
|
||||||
*/
|
*/
|
||||||
OSS_ACCESS_SECRET("oss_aliyun_access_secret", String.class, "");
|
OSS_ACCESS_SECRET("oss_aliyun_access_secret", String.class, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aliyun oss style rule
|
||||||
|
*/
|
||||||
|
OSS_STYLE_RULE("oss_aliyun_style_rule", String.class, "");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|
|
@ -8,17 +8,17 @@ package run.halo.app.model.properties;
|
||||||
*/
|
*/
|
||||||
public enum QnYunProperties implements PropertyEnum {
|
public enum QnYunProperties implements PropertyEnum {
|
||||||
|
|
||||||
ZONE("oss_qiniu_zone", String.class, "auto"),
|
OSS_ZONE("oss_qiniu_zone", String.class, "auto"),
|
||||||
|
|
||||||
ACCESS_KEY("oss_qiniu_access_key", String.class, ""),
|
OSS_ACCESS_KEY("oss_qiniu_access_key", String.class, ""),
|
||||||
|
|
||||||
SECRET_KEY("oss_qiniu_secret_key", String.class, ""),
|
OSS_SECRET_KEY("oss_qiniu_secret_key", String.class, ""),
|
||||||
|
|
||||||
DOMAIN("oss_qiniu_domain", String.class, ""),
|
OSS_DOMAIN("oss_qiniu_domain", String.class, ""),
|
||||||
|
|
||||||
BUCKET("oss_qiniu_bucket", String.class, ""),
|
OSS_BUCKET("oss_qiniu_bucket", String.class, ""),
|
||||||
|
|
||||||
SMALL_URL("oss_qiniu_small_url", String.class, "");
|
OSS_STYLE_RULE("oss_qiniu_style_rule", String.class, "");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public enum UpYunProperties implements PropertyEnum {
|
||||||
|
|
||||||
OSS_OPERATOR("oss_upyun_operator", String.class, ""),
|
OSS_OPERATOR("oss_upyun_operator", String.class, ""),
|
||||||
|
|
||||||
OSS_SMALL_URL("oss_upyun_small_url", String.class, "");
|
OSS_STYLE_RULE("oss_upyun_style_rule", String.class, "");
|
||||||
|
|
||||||
private final String defaultValue;
|
private final String defaultValue;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
|
@ -312,7 +312,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Zone getQnYunZone() {
|
public Zone getQnYunZone() {
|
||||||
return getByProperty(QnYunProperties.ZONE).map(qiniuZone -> {
|
return getByProperty(QnYunProperties.OSS_ZONE).map(qiniuZone -> {
|
||||||
|
|
||||||
Zone zone;
|
Zone zone;
|
||||||
switch (qiniuZone.toString()) {
|
switch (qiniuZone.toString()) {
|
||||||
|
|
Loading…
Reference in New Issue