mirror of https://github.com/halo-dev/halo
Fixed file upload handler.
parent
f62f3f5c4a
commit
7f3177eddc
|
@ -25,6 +25,7 @@ import java.util.Objects;
|
||||||
* AliYun file handler.
|
* AliYun file handler.
|
||||||
*
|
*
|
||||||
* @author MyFaith
|
* @author MyFaith
|
||||||
|
* @author ryanwang
|
||||||
* @date 2019-04-04 00:06:13
|
* @date 2019-04-04 00:06:13
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -46,8 +47,9 @@ 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);
|
||||||
|
String ossStyleRule = optionService.getByPropertyOrDefault(AliYunProperties.OSS_STYLE_RULE,String.class,"");
|
||||||
|
String ossThumbnailStyleRule = optionService.getByPropertyOrDefault(AliYunProperties.OSS_THUMBNAIL_STYLE_RULE,String.class,"");
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
OSS ossClient = new OSSClientBuilder().build(ossEndPoint, ossAccessKey, ossAccessSecret);
|
OSS ossClient = new OSSClientBuilder().build(ossEndPoint, ossAccessKey, ossAccessSecret);
|
||||||
|
@ -68,7 +70,7 @@ public class AliYunFileHandler implements FileHandler {
|
||||||
// Response result
|
// Response result
|
||||||
UploadResult uploadResult = new UploadResult();
|
UploadResult uploadResult = new UploadResult();
|
||||||
uploadResult.setFilename(basename);
|
uploadResult.setFilename(basename);
|
||||||
uploadResult.setFilePath(filePath);
|
uploadResult.setFilePath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
|
||||||
uploadResult.setKey(upFilePath);
|
uploadResult.setKey(upFilePath);
|
||||||
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
||||||
uploadResult.setSuffix(extension);
|
uploadResult.setSuffix(extension);
|
||||||
|
@ -79,7 +81,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(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
|
uploadResult.setThumbPath(StringUtils.isBlank(ossThumbnailStyleRule) ? filePath : filePath + ossThumbnailStyleRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploadResult;
|
return uploadResult;
|
||||||
|
@ -106,7 +108,6 @@ 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 ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
OSS ossClient = new OSSClientBuilder().build(ossEndPoint, ossAccessKey, ossAccessSecret);
|
OSS ossClient = new OSSClientBuilder().build(ossEndPoint, ossAccessKey, ossAccessSecret);
|
||||||
|
|
|
@ -43,17 +43,18 @@ public class BaiDuYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(file, "Multipart file must not be null");
|
Assert.notNull(file, "Multipart file must not be null");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
String ossEndPoint = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_ENDPOINT).toString();
|
String bosEndPoint = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_ENDPOINT).toString();
|
||||||
String ossAccessKey = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_ACCESS_KEY).toString();
|
String bosAccessKey = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_ACCESS_KEY).toString();
|
||||||
String ossAccessSecret = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_ACCESS_SECRET).toString();
|
String bosSecretKey = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_SECRET_KEY).toString();
|
||||||
String ossBucketName = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_BUCKET_NAME).toString();
|
String bosBucketName = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_BUCKET_NAME).toString();
|
||||||
String ossStyleRule = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_STYLE_RULE).toString();
|
String bosStyleRule = optionService.getByPropertyOrDefault(BaiDuYunProperties.BOS_STYLE_RULE, String.class, "");
|
||||||
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
String bosThumbnailStyleRule = optionService.getByPropertyOrDefault(BaiDuYunProperties.BOS_STYLE_RULE, String.class, "");
|
||||||
|
String bosSource = StringUtils.join("https://", bosBucketName, "." + bosEndPoint);
|
||||||
|
|
||||||
|
|
||||||
BosClientConfiguration config = new BosClientConfiguration();
|
BosClientConfiguration config = new BosClientConfiguration();
|
||||||
config.setCredentials(new DefaultBceCredentials(ossAccessKey, ossAccessSecret));
|
config.setCredentials(new DefaultBceCredentials(bosAccessKey, bosSecretKey));
|
||||||
config.setEndpoint(ossEndPoint);
|
config.setEndpoint(bosEndPoint);
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
BosClient client = new BosClient(config);
|
BosClient client = new BosClient(config);
|
||||||
|
@ -63,10 +64,10 @@ public class BaiDuYunFileHandler implements FileHandler {
|
||||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||||
String upFilePath = StringUtils.join(basename, "_", timestamp, ".", extension);
|
String upFilePath = StringUtils.join(basename, "_", timestamp, ".", extension);
|
||||||
String filePath = StringUtils.join(StringUtils.appendIfMissing(ossSource, "/"), upFilePath);
|
String filePath = StringUtils.join(StringUtils.appendIfMissing(bosSource, "/"), upFilePath);
|
||||||
|
|
||||||
// Upload
|
// Upload
|
||||||
PutObjectResponse putObjectResponseFromInputStream = client.putObject(ossBucketName, upFilePath, file.getInputStream());
|
PutObjectResponse putObjectResponseFromInputStream = client.putObject(bosBucketName, upFilePath, file.getInputStream());
|
||||||
if (putObjectResponseFromInputStream == null) {
|
if (putObjectResponseFromInputStream == null) {
|
||||||
throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到百度云失败 ");
|
throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到百度云失败 ");
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,7 @@ public class BaiDuYunFileHandler implements FileHandler {
|
||||||
// Response result
|
// Response result
|
||||||
UploadResult uploadResult = new UploadResult();
|
UploadResult uploadResult = new UploadResult();
|
||||||
uploadResult.setFilename(basename);
|
uploadResult.setFilename(basename);
|
||||||
uploadResult.setFilePath(filePath);
|
uploadResult.setFilePath(StringUtils.isBlank(bosStyleRule) ? filePath : filePath + bosStyleRule);
|
||||||
uploadResult.setKey(upFilePath);
|
uploadResult.setKey(upFilePath);
|
||||||
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
||||||
uploadResult.setSuffix(extension);
|
uploadResult.setSuffix(extension);
|
||||||
|
@ -85,7 +86,7 @@ public class BaiDuYunFileHandler 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(ossStyleRule) ? filePath : filePath + ossStyleRule);
|
uploadResult.setThumbPath(StringUtils.isBlank(bosThumbnailStyleRule) ? filePath : filePath + bosThumbnailStyleRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploadResult;
|
return uploadResult;
|
||||||
|
@ -101,21 +102,20 @@ public class BaiDuYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(key, "File key must not be blank");
|
Assert.notNull(key, "File key must not be blank");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
String ossEndPoint = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_ENDPOINT).toString();
|
String bosEndPoint = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_ENDPOINT).toString();
|
||||||
String ossAccessKey = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_ACCESS_KEY).toString();
|
String bosAccessKey = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_ACCESS_KEY).toString();
|
||||||
String ossAccessSecret = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_ACCESS_SECRET).toString();
|
String bosSecretKey = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_SECRET_KEY).toString();
|
||||||
String ossBucketName = optionService.getByPropertyOfNonNull(BaiDuYunProperties.OSS_BUCKET_NAME).toString();
|
String bosBucketName = optionService.getByPropertyOfNonNull(BaiDuYunProperties.BOS_BUCKET_NAME).toString();
|
||||||
String ossSource = StringUtils.join("https://", ossBucketName, "." + ossEndPoint);
|
|
||||||
|
|
||||||
BosClientConfiguration config = new BosClientConfiguration();
|
BosClientConfiguration config = new BosClientConfiguration();
|
||||||
config.setCredentials(new DefaultBceCredentials(ossAccessKey, ossAccessSecret));
|
config.setCredentials(new DefaultBceCredentials(bosAccessKey, bosSecretKey));
|
||||||
config.setEndpoint(ossEndPoint);
|
config.setEndpoint(bosEndPoint);
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
BosClient client = new BosClient(config);
|
BosClient client = new BosClient(config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.deleteObject(ossBucketName, key);
|
client.deleteObject(bosBucketName, key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new FileOperationException("附件 " + key + " 从百度云删除失败", e);
|
throw new FileOperationException("附件 " + key + " 从百度云删除失败", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import static run.halo.app.handler.file.FileHandler.isImageType;
|
||||||
* Qi niu yun file handler.
|
* Qi niu yun file handler.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
|
* @author ryanwang
|
||||||
* @date 3/27/19
|
* @date 3/27/19
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -58,6 +59,7 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_BUCKET).toString();
|
String bucket = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_BUCKET).toString();
|
||||||
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_DOMAIN).toString();
|
String domain = optionService.getByPropertyOfNonNull(QnYunProperties.OSS_DOMAIN).toString();
|
||||||
String styleRule = optionService.getByPropertyOrDefault(QnYunProperties.OSS_STYLE_RULE, String.class, "");
|
String styleRule = optionService.getByPropertyOrDefault(QnYunProperties.OSS_STYLE_RULE, String.class, "");
|
||||||
|
String thumbnailStyleRule = optionService.getByPropertyOrDefault(QnYunProperties.OSS_THUMBNAIL_STYLE_RULE, String.class, "");
|
||||||
|
|
||||||
// Create configuration
|
// Create configuration
|
||||||
Configuration configuration = new Configuration(zone);
|
Configuration configuration = new Configuration(zone);
|
||||||
|
@ -103,7 +105,7 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
// Build upload result
|
// Build upload result
|
||||||
UploadResult result = new UploadResult();
|
UploadResult result = new UploadResult();
|
||||||
result.setFilename(basename);
|
result.setFilename(basename);
|
||||||
result.setFilePath(filePath);
|
result.setFilePath(StringUtils.isBlank(styleRule) ? filePath : filePath + styleRule);
|
||||||
result.setKey(putSet.getKey());
|
result.setKey(putSet.getKey());
|
||||||
result.setSuffix(extension);
|
result.setSuffix(extension);
|
||||||
result.setWidth(putSet.getWidth());
|
result.setWidth(putSet.getWidth());
|
||||||
|
@ -112,7 +114,7 @@ public class QnYunFileHandler implements FileHandler {
|
||||||
result.setSize(file.getSize());
|
result.setSize(file.getSize());
|
||||||
|
|
||||||
if (isImageType(result.getMediaType())) {
|
if (isImageType(result.getMediaType())) {
|
||||||
result.setThumbPath(StringUtils.isBlank(styleRule) ? filePath : filePath + styleRule);
|
result.setThumbPath(StringUtils.isBlank(thumbnailStyleRule) ? filePath : filePath + thumbnailStyleRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package run.halo.app.handler.file;
|
package run.halo.app.handler.file;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.qcloud.cos.COSClient;
|
import com.qcloud.cos.COSClient;
|
||||||
import com.qcloud.cos.ClientConfig;
|
import com.qcloud.cos.ClientConfig;
|
||||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||||
|
@ -30,6 +29,7 @@ import java.util.Objects;
|
||||||
* TencentYun file handler.
|
* TencentYun file handler.
|
||||||
*
|
*
|
||||||
* @author wangya
|
* @author wangya
|
||||||
|
* @author ryanwang
|
||||||
* @date 2019-07-25
|
* @date 2019-07-25
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -47,21 +47,18 @@ public class TencentYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(file, "Multipart file must not be null");
|
Assert.notNull(file, "Multipart file must not be null");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
String ossRegion = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_REGION).toString();
|
String cosRegion = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_REGION).toString();
|
||||||
String ossAccessKey = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_ACCESS_KEY).toString();
|
String cosSecretId = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_SECRET_ID).toString();
|
||||||
String ossAccessSecret = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_ACCESS_SECRET).toString();
|
String cosSecretKey = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_SECRET_KEY).toString();
|
||||||
String ossBucketName = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_BUCKET_NAME).toString();
|
String cosBucketName = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_BUCKET_NAME).toString();
|
||||||
String ossStyleRule = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_STYLE_RULE).toString();
|
String cosSource = StringUtils.join("https://", cosBucketName, ".cos." + cosRegion + ".myqcloud.com");
|
||||||
String ossSource = StringUtils.join("https://", ossBucketName, ".cos." + ossRegion+".myqcloud.com");
|
|
||||||
|
|
||||||
//get file attribute
|
//get file attribute
|
||||||
long size = file.getSize();
|
long size = file.getSize();
|
||||||
String contentType = file.getContentType();
|
String contentType = file.getContentType();
|
||||||
|
|
||||||
|
COSCredentials cred = new BasicCOSCredentials(cosSecretId, cosSecretKey);
|
||||||
|
Region region = new Region(cosRegion);
|
||||||
COSCredentials cred = new BasicCOSCredentials(ossAccessKey, ossAccessSecret);
|
|
||||||
Region region = new Region(ossRegion);
|
|
||||||
ClientConfig clientConfig = new ClientConfig(region);
|
ClientConfig clientConfig = new ClientConfig(region);
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,13 +66,12 @@ public class TencentYunFileHandler implements FileHandler {
|
||||||
COSClient cosClient = new COSClient(cred, clientConfig);
|
COSClient cosClient = new COSClient(cred, clientConfig);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String basename = FilenameUtils.getBasename(file.getOriginalFilename());
|
String basename = FilenameUtils.getBasename(file.getOriginalFilename());
|
||||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||||
String upFilePath = StringUtils.join(basename, "_", timestamp, ".", extension);
|
String upFilePath = StringUtils.join(basename, "_", timestamp, ".", extension);
|
||||||
String filePath = StringUtils.join(StringUtils.appendIfMissing(ossSource, "/"), upFilePath);
|
String filePath = StringUtils.join(StringUtils.appendIfMissing(cosSource, "/"), upFilePath);
|
||||||
|
|
||||||
// Upload
|
// Upload
|
||||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||||
|
@ -83,7 +79,7 @@ public class TencentYunFileHandler implements FileHandler {
|
||||||
objectMetadata.setContentLength(size);
|
objectMetadata.setContentLength(size);
|
||||||
// 设置 Content type, 默认是 application/octet-stream
|
// 设置 Content type, 默认是 application/octet-stream
|
||||||
objectMetadata.setContentType(contentType);
|
objectMetadata.setContentType(contentType);
|
||||||
PutObjectResult putObjectResponseFromInputStream = cosClient.putObject(ossBucketName, upFilePath, file.getInputStream(),objectMetadata);
|
PutObjectResult putObjectResponseFromInputStream = cosClient.putObject(cosBucketName, upFilePath, file.getInputStream(), objectMetadata);
|
||||||
if (putObjectResponseFromInputStream == null) {
|
if (putObjectResponseFromInputStream == null) {
|
||||||
throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到腾讯云失败 ");
|
throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到腾讯云失败 ");
|
||||||
}
|
}
|
||||||
|
@ -102,7 +98,7 @@ public class TencentYunFileHandler 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(ossStyleRule) ? filePath : filePath + ossStyleRule);
|
uploadResult.setThumbPath(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploadResult;
|
return uploadResult;
|
||||||
|
@ -118,22 +114,20 @@ public class TencentYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(key, "File key must not be blank");
|
Assert.notNull(key, "File key must not be blank");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
String ossRegion = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_REGION).toString();
|
String cosRegion = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_REGION).toString();
|
||||||
String ossAccessKey = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_ACCESS_KEY).toString();
|
String cosSecretId = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_SECRET_ID).toString();
|
||||||
String ossAccessSecret = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_ACCESS_SECRET).toString();
|
String cosSecretKey = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_SECRET_KEY).toString();
|
||||||
String ossBucketName = optionService.getByPropertyOfNonNull(TencentYunProperties.OSS_BUCKET_NAME).toString();
|
String cosBucketName = optionService.getByPropertyOfNonNull(TencentYunProperties.COS_BUCKET_NAME).toString();
|
||||||
String ossSource = StringUtils.join("https://", ossBucketName, ".cos." + ossRegion+".myqcloud.com");
|
|
||||||
|
|
||||||
COSCredentials cred = new BasicCOSCredentials(ossAccessKey, ossAccessSecret);
|
COSCredentials cred = new BasicCOSCredentials(cosSecretId, cosSecretKey);
|
||||||
Region region = new Region(ossRegion);
|
Region region = new Region(cosRegion);
|
||||||
ClientConfig clientConfig = new ClientConfig(region);
|
ClientConfig clientConfig = new ClientConfig(region);
|
||||||
|
|
||||||
|
|
||||||
// Init OSS client
|
// Init OSS client
|
||||||
COSClient cosClient = new COSClient(cred, clientConfig);
|
COSClient cosClient = new COSClient(cred, clientConfig);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cosClient.deleteObject(ossBucketName, key);
|
cosClient.deleteObject(cosBucketName, key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new FileOperationException("附件 " + key + " 从腾讯云删除失败", e);
|
throw new FileOperationException("附件 " + key + " 从腾讯云删除失败", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
// Build upload result
|
// Build upload result
|
||||||
UploadResult uploadResult = new UploadResult();
|
UploadResult uploadResult = new UploadResult();
|
||||||
uploadResult.setFilename(basename);
|
uploadResult.setFilename(basename);
|
||||||
uploadResult.setFilePath(StringUtils.isBlank(filePath) ? filePath : filePath + ossStyleRule);
|
uploadResult.setFilePath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
|
||||||
uploadResult.setKey(upFilePath);
|
uploadResult.setKey(upFilePath);
|
||||||
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
||||||
uploadResult.setSuffix(extension);
|
uploadResult.setSuffix(extension);
|
||||||
|
@ -88,7 +88,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(ossStyleRule) ? filePath : filePath + ossThumbnailStyleRule);
|
uploadResult.setThumbPath(StringUtils.isBlank(ossThumbnailStyleRule) ? filePath : filePath + ossThumbnailStyleRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploadResult;
|
return uploadResult;
|
||||||
|
@ -102,7 +102,6 @@ public class UpYunFileHandler implements FileHandler {
|
||||||
Assert.notNull(key, "File key must not be blank");
|
Assert.notNull(key, "File key must not be blank");
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
// String ossSource = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_SOURCE).toString();
|
|
||||||
String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD).toString();
|
String ossPassword = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_PASSWORD).toString();
|
||||||
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString();
|
String ossBucket = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_BUCKET).toString();
|
||||||
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
|
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
|
||||||
|
|
|
@ -4,6 +4,7 @@ package run.halo.app.model.properties;
|
||||||
* AliYun properties.
|
* AliYun properties.
|
||||||
*
|
*
|
||||||
* @author MyFaith
|
* @author MyFaith
|
||||||
|
* @author ryanwang
|
||||||
* @date 2019-04-04 00:00:56
|
* @date 2019-04-04 00:00:56
|
||||||
*/
|
*/
|
||||||
public enum AliYunProperties implements PropertyEnum {
|
public enum AliYunProperties implements PropertyEnum {
|
||||||
|
@ -31,7 +32,12 @@ public enum AliYunProperties implements PropertyEnum {
|
||||||
/**
|
/**
|
||||||
* Aliyun oss style rule
|
* Aliyun oss style rule
|
||||||
*/
|
*/
|
||||||
OSS_STYLE_RULE("oss_aliyun_style_rule", String.class, "");
|
OSS_STYLE_RULE("oss_aliyun_style_rule", String.class, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aliyun oss thumbnail style rule
|
||||||
|
*/
|
||||||
|
OSS_THUMBNAIL_STYLE_RULE("oss_aliyun_thumbnail_style_rule", String.class, "");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|
|
@ -4,34 +4,40 @@ package run.halo.app.model.properties;
|
||||||
* BaiDuYun properties.
|
* BaiDuYun properties.
|
||||||
*
|
*
|
||||||
* @author wangya
|
* @author wangya
|
||||||
|
* @author ryanwang
|
||||||
* @date 2019-07-19
|
* @date 2019-07-19
|
||||||
*/
|
*/
|
||||||
public enum BaiDuYunProperties implements PropertyEnum {
|
public enum BaiDuYunProperties implements PropertyEnum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaiDuyun oss endpoint.
|
* Baidu yun bos endpoint.
|
||||||
*/
|
*/
|
||||||
OSS_ENDPOINT("oss_baiduyun_endpoint", String.class, ""),
|
BOS_ENDPOINT("bos_baiduyun_endpoint", String.class, ""),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaiDuyun oss bucket name.
|
* Baidu yun bos bucket name.
|
||||||
*/
|
*/
|
||||||
OSS_BUCKET_NAME("oss_baiduyun_bucket_name", String.class, ""),
|
BOS_BUCKET_NAME("bos_baiduyun_bucket_name", String.class, ""),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaiDuyun oss access key.
|
* Baidu yun bos access key.
|
||||||
*/
|
*/
|
||||||
OSS_ACCESS_KEY("oss_baiduyun_access_key", String.class, ""),
|
BOS_ACCESS_KEY("bos_baiduyun_access_key", String.class, ""),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaiDuyun oss access secret.
|
* Baidu yun bos secret key.
|
||||||
*/
|
*/
|
||||||
OSS_ACCESS_SECRET("oss_baiduyun_access_secret", String.class, ""),
|
BOS_SECRET_KEY("bos_baiduyun_secret_key", String.class, ""),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaiDuyun oss style rule
|
* Baidu yun bos style rule.
|
||||||
*/
|
*/
|
||||||
OSS_STYLE_RULE("oss_baiduyun_style_rule", String.class, "");
|
BOS_STYLE_RULE("bos_baiduyun_style_rule", String.class, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Baidu yun bos thumbnail style rule.
|
||||||
|
*/
|
||||||
|
BOS_THUMBNAIL_STYLE_RULE("bos_baiduyun_thumbnail_style_rule", String.class, "");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ package run.halo.app.model.properties;
|
||||||
* Qi niu yun properties.
|
* Qi niu yun properties.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
|
* @author ryanwang
|
||||||
* @date 3/26/19
|
* @date 3/26/19
|
||||||
*/
|
*/
|
||||||
public enum QnYunProperties implements PropertyEnum {
|
public enum QnYunProperties implements PropertyEnum {
|
||||||
|
@ -18,7 +19,9 @@ public enum QnYunProperties implements PropertyEnum {
|
||||||
|
|
||||||
OSS_BUCKET("oss_qiniu_bucket", String.class, ""),
|
OSS_BUCKET("oss_qiniu_bucket", String.class, ""),
|
||||||
|
|
||||||
OSS_STYLE_RULE("oss_qiniu_style_rule", String.class, "");
|
OSS_STYLE_RULE("oss_qiniu_style_rule", String.class, ""),
|
||||||
|
|
||||||
|
OSS_THUMBNAIL_STYLE_RULE("oss_qiniu_thumbnail_style_rule", String.class, "");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|
|
@ -4,34 +4,30 @@ package run.halo.app.model.properties;
|
||||||
* TencentYun properties.
|
* TencentYun properties.
|
||||||
*
|
*
|
||||||
* @author wangya
|
* @author wangya
|
||||||
|
* @author ryanwang
|
||||||
* @date 2019-07-25
|
* @date 2019-07-25
|
||||||
*/
|
*/
|
||||||
public enum TencentYunProperties implements PropertyEnum {
|
public enum TencentYunProperties implements PropertyEnum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tencentyun oss endpoint.
|
* Tencentyun cos endpoint.
|
||||||
*/
|
*/
|
||||||
OSS_REGION("oss_tencentyun_region", String.class, ""),
|
COS_REGION("cos_tencentyun_region", String.class, ""),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tencentyun oss bucket name.
|
* Tencentyun cos bucket name.
|
||||||
*/
|
*/
|
||||||
OSS_BUCKET_NAME("oss_tencentyun_bucket_name", String.class, ""),
|
COS_BUCKET_NAME("cos_tencentyun_bucket_name", String.class, ""),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tencentyun oss access key.
|
* Tencentyun cos secret id.
|
||||||
*/
|
*/
|
||||||
OSS_ACCESS_KEY("oss_tencentyun_access_key", String.class, ""),
|
COS_SECRET_ID("cos_tencentyun_secret_id", String.class, ""),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tencentyun oss access secret.
|
* Tencentyun cos secret key.
|
||||||
*/
|
*/
|
||||||
OSS_ACCESS_SECRET("oss_tencentyun_access_secret", String.class, ""),
|
COS_SECRET_KEY("cos_tencentyun_secret_key", String.class, "");
|
||||||
|
|
||||||
/**
|
|
||||||
* Tencentyun oss style rule
|
|
||||||
*/
|
|
||||||
OSS_STYLE_RULE("oss_tencentyun_style_rule", String.class, "");
|
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue