Fixed ali oss upload error.

pull/172/head
ruibaby 2019-05-30 23:23:28 +08:00
parent 0c8955dfcf
commit 8e9f4dff06
7 changed files with 29 additions and 22 deletions

View File

@ -46,6 +46,7 @@ public class AliYunFileHandler implements FileHandler {
String ossAccessKey = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_KEY).toString();
String ossAccessSecret = optionService.getByPropertyOfNonNull(AliYunProperties.OSS_ACCESS_SECRET).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);
// Init OSS client
@ -78,7 +79,7 @@ public class AliYunFileHandler implements FileHandler {
BufferedImage image = ImageIO.read(file.getInputStream());
uploadResult.setWidth(image.getWidth());
uploadResult.setHeight(image.getHeight());
uploadResult.setThumbPath(filePath);
uploadResult.setThumbPath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
}
return uploadResult;

View File

@ -53,11 +53,11 @@ public class QnYunFileHandler implements FileHandler {
// Get all config
Zone zone = optionService.getQnYunZone();
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString();
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString();
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString();
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.DOMAIN).toString();
String smallUrl = optionService.getByPropertyOrDefault(QnYunProperties.SMALL_URL, String.class, "");
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_ACCESS_KEY).toString();
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_SECRET_KEY).toString();
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_BUCKET).toString();
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_DOMAIN).toString();
String styleRule = optionService.getByPropertyOrDefault(QnYunProperties.OSS_STYLE_RULE, String.class, "");
// Create configuration
Configuration configuration = new Configuration(zone);
@ -109,9 +109,10 @@ public class QnYunFileHandler implements FileHandler {
result.setWidth(putSet.getWidth());
result.setHeight(putSet.getHeight());
result.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
result.setSize(file.getSize());
if (isImageType(result.getMediaType())) {
result.setThumbPath(StringUtils.isBlank(smallUrl) ? filePath : filePath + smallUrl);
result.setThumbPath(StringUtils.isBlank(styleRule) ? filePath : filePath + styleRule);
}
return result;
@ -130,9 +131,9 @@ public class QnYunFileHandler implements FileHandler {
// Get all config
Zone zone = optionService.getQnYunZone();
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.ACCESS_KEY).toString();
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.SECRET_KEY).toString();
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.BUCKET).toString();
String accessKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_ACCESS_KEY).toString();
String secretKey = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_SECRET_KEY).toString();
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_BUCKET).toString();
// Create configuration
Configuration configuration = new Configuration(zone);

View File

@ -44,8 +44,8 @@ public class UpYunFileHandler implements FileHandler {
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString();
String ossDomain = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_DOMAIN).toString();
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
// small url can be null
String ossSmallUrl = optionService.getByPropertyOrDefault(UpYunProperties.OSS_SMALL_URL, String.class, "");
// style rule can be null
String ossStyleRule = optionService.getByPropertyOrDefault(UpYunProperties.OSS_STYLE_RULE, String.class, "");
// Create up yun
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
@ -86,7 +86,7 @@ public class UpYunFileHandler implements FileHandler {
BufferedImage image = ImageIO.read(file.getInputStream());
uploadResult.setWidth(image.getWidth());
uploadResult.setHeight(image.getHeight());
uploadResult.setThumbPath(StringUtils.isBlank(ossSmallUrl) ? filePath : filePath + ossSmallUrl);
uploadResult.setThumbPath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
}
return uploadResult;

View File

@ -26,7 +26,12 @@ public enum AliYunProperties implements PropertyEnum {
/**
* 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;

View File

@ -8,17 +8,17 @@ package run.halo.app.model.properties;
*/
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;

View File

@ -18,7 +18,7 @@ public enum UpYunProperties implements PropertyEnum {
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 String value;

View File

@ -312,7 +312,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
@Override
public Zone getQnYunZone() {
return getByProperty(QnYunProperties.ZONE).map(qiniuZone -> {
return getByProperty(QnYunProperties.OSS_ZONE).map(qiniuZone -> {
Zone zone;
switch (qiniuZone.toString()) {