♻️ Refactoring code. common-minio -> common-oss 支持V3协议 OSS

This commit is contained in:
lzg committed 2020-05-23 14:25:29 +08:00
1 parent 7103be131c
commit 19cd0c09d4
19 files changed
+52 -610

No files matched your search

+2 -7
View File
@@ -70,12 +70,7 @@
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-minio</artifactId>
<version>${pigx.version}</version>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-aws</artifactId>
<artifactId>pigx-common-oss</artifactId>
<version>${pigx.version}</version>
</dependency>
<dependency>
@@ -223,7 +218,7 @@
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>aliyun-plugin</id>
-24
View File
@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common</artifactId>
<version>3.9.0-SNAPSHOT</version>
</parent>
<artifactId>pigx-common-minio</artifactId>
<packaging>jar</packaging>
<description>pigx 文件系统依赖</description>
<dependencies>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>${minio.version}</version>
</dependency>
</dependencies>
</project>
@@ -1,56 +0,0 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.minio;
import com.pig4cloud.pigx.common.minio.http.MinioEndpoint;
import com.pig4cloud.pigx.common.minio.service.MinioTemplate;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
* minio 自动配置类
*
* @author lengleng
*/
@AllArgsConstructor
@EnableConfigurationProperties({MinioProperties.class})
public class MinioAutoConfiguration {
private final MinioProperties properties;
@Bean
@ConditionalOnMissingBean(MinioTemplate.class)
@ConditionalOnProperty(name = "minio.url")
MinioTemplate template() {
return new MinioTemplate(
properties.getUrl(),
properties.getAccessKey(),
properties.getSecretKey()
);
}
@Bean
@ConditionalOnProperty(name = "minio.endpoint.enable", havingValue = "true")
public MinioEndpoint minioEndpoint(MinioTemplate template) {
return new MinioEndpoint(template);
}
}
@@ -1,46 +0,0 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.minio;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* minio 配置信息
*
* @author lengleng
*/
@Data
@ConfigurationProperties(prefix = "minio")
public class MinioProperties {
/**
* minio 服务地址 http://ip:port
*/
private String url;
/**
* 用户名
*/
private String accessKey;
/**
* 密码
*/
private String secretKey;
}
@@ -1,127 +0,0 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.minio.http;
import com.pig4cloud.pigx.common.minio.service.MinioTemplate;
import com.pig4cloud.pigx.common.minio.vo.MinioItem;
import com.pig4cloud.pigx.common.minio.vo.MinioObject;
import io.minio.messages.Bucket;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* minio 对外提供服务端点
*
* @author lengleng
* <p>
* minio.endpoint.enable
*/
@RestController
@AllArgsConstructor
@RequestMapping("${minio.endpoint.name:/minio}")
public class MinioEndpoint {
private final MinioTemplate template;
/**
* Bucket Endpoints
*/
@SneakyThrows
@PostMapping("/bucket/{bucketName}")
public Bucket createBucker(@PathVariable String bucketName) {
template.createBucket(bucketName);
return template.getBucket(bucketName).get();
}
@SneakyThrows
@GetMapping("/bucket")
public List<Bucket> getBuckets() {
return template.getAllBuckets();
}
@SneakyThrows
@GetMapping("/bucket/{bucketName}")
public Bucket getBucket(@PathVariable String bucketName) {
return template.getBucket(bucketName).orElseThrow(() -> new IllegalArgumentException("Bucket Name not found!"));
}
@SneakyThrows
@DeleteMapping("/bucket/{bucketName}")
@ResponseStatus(HttpStatus.ACCEPTED)
public void deleteBucket(@PathVariable String bucketName) {
template.removeBucket(bucketName);
}
/**
* Object Endpoints
*/
@SneakyThrows
@PostMapping("/object/{bucketName}")
public MinioObject createObject(@RequestBody MultipartFile object, @PathVariable String bucketName) {
String name = object.getOriginalFilename();
template.putObject(bucketName, name, object.getInputStream(), object.getSize(), object.getContentType());
return new MinioObject(template.getObjectInfo(bucketName, name));
}
@SneakyThrows
@PostMapping("/object/{bucketName}/{objectName}")
public MinioObject createObject(@RequestBody MultipartFile object, @PathVariable String bucketName, @PathVariable String objectName) {
template.putObject(bucketName, objectName, object.getInputStream(), object.getSize(), object.getContentType());
return new MinioObject(template.getObjectInfo(bucketName, objectName));
}
@SneakyThrows
@GetMapping("/object/{bucketName}/{objectName}")
public List<MinioItem> filterObject(@PathVariable String bucketName, @PathVariable String objectName) {
return template.getAllObjectsByPrefix(bucketName, objectName, true);
}
@SneakyThrows
@GetMapping("/object/{bucketName}/{objectName}/{expires}")
public Map<String, Object> getObject(@PathVariable String bucketName, @PathVariable String objectName, @PathVariable Integer expires) {
Map<String, Object> responseBody = new HashMap<>(8);
// Put Object info
responseBody.put("bucket", bucketName);
responseBody.put("object", objectName);
responseBody.put("url", template.getObjectURL(bucketName, objectName, expires));
responseBody.put("expires", expires);
return responseBody;
}
@SneakyThrows
@ResponseStatus(HttpStatus.ACCEPTED)
@DeleteMapping("/object/{bucketName}/{objectName}/")
public void deleteObject(@PathVariable String bucketName, @PathVariable String objectName) {
template.removeObject(bucketName, objectName);
}
}
@@ -1,187 +0,0 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.minio.service;
import com.pig4cloud.pigx.common.minio.vo.MinioItem;
import io.minio.MinioClient;
import io.minio.ObjectStat;
import io.minio.Result;
import io.minio.messages.Bucket;
import io.minio.messages.Item;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* minio 交互类
*
* @author lengleng
*/
@RequiredArgsConstructor
public class MinioTemplate implements InitializingBean {
private final String endpoint;
private final String accessKey;
private final String secretKey;
private MinioClient client;
/**
* 创建bucket
*
* @param bucketName bucket名称
*/
@SneakyThrows
public void createBucket(String bucketName) {
if (!client.bucketExists(bucketName)) {
client.makeBucket(bucketName);
}
}
/**
* 获取全部bucket
* <p>
* https://docs.minio.io/cn/java-client-api-reference.html#listBuckets
*/
@SneakyThrows
public List<Bucket> getAllBuckets() {
return client.listBuckets();
}
/**
* @param bucketName bucket名称
*/
@SneakyThrows
public Optional<Bucket> getBucket(String bucketName) {
return client.listBuckets().stream().filter(b -> b.name().equals(bucketName)).findFirst();
}
/**
* @param bucketName bucket名称
*/
@SneakyThrows
public void removeBucket(String bucketName) {
client.removeBucket(bucketName);
}
/**
* 根据文件前置查询文件
*
* @param bucketName bucket名称
* @param prefix 前缀
* @param recursive 是否递归查询
* @return MinioItem 列表
*/
@SneakyThrows
public List<MinioItem> getAllObjectsByPrefix(String bucketName, String prefix, boolean recursive) {
List<MinioItem> objectList = new ArrayList<>();
Iterable<Result<Item>> objectsIterator = client
.listObjects(bucketName, prefix, recursive);
for (Result<Item> itemResult : objectsIterator) {
objectList.add(new MinioItem(itemResult.get()));
}
return objectList;
}
/**
* 获取文件外链
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @param expires 过期时间 <=7
* @return url
*/
@SneakyThrows
public String getObjectURL(String bucketName, String objectName, Integer expires) {
return client.presignedGetObject(bucketName, objectName, expires);
}
/**
* 获取文件
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @return 二进制流
*/
@SneakyThrows
public InputStream getObject(String bucketName, String objectName) {
return client.getObject(bucketName, objectName);
}
/**
* 上传文件
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @param stream 文件流
* @throws Exception https://docs.minio.io/cn/java-client-api-reference.html#putObject
*/
public void putObject(String bucketName, String objectName, InputStream stream) throws Exception {
client.putObject(bucketName, objectName, stream, (long) stream.available(), null, null, "application/octet-stream");
}
/**
* 上传文件
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @param stream 文件流
* @param size 大小
* @param contextType 类型
* @throws Exception https://docs.minio.io/cn/java-client-api-reference.html#putObject
*/
public void putObject(String bucketName, String objectName, InputStream stream, long size, String contextType) throws Exception {
client.putObject(bucketName, objectName, stream, size, null, null, contextType);
}
/**
* 获取文件信息
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @throws Exception https://docs.minio.io/cn/java-client-api-reference.html#statObject
*/
public ObjectStat getObjectInfo(String bucketName, String objectName) throws Exception {
return client.statObject(bucketName, objectName);
}
/**
* 删除文件
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @throws Exception https://docs.minio.io/cn/java-client-api-reference.html#removeObject
*/
public void removeObject(String bucketName, String objectName) throws Exception {
client.removeObject(bucketName, objectName);
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.hasText(endpoint, "Minio url 为空");
Assert.hasText(accessKey, "Minio accessKey为空");
Assert.hasText(secretKey, "Minio secretKey为空");
this.client = new MinioClient(endpoint, accessKey, secretKey);
}
}
@@ -1,53 +0,0 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.minio.vo;
import io.minio.messages.Item;
import io.minio.messages.Owner;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Date;
/**
* minio 桶中的对象信息
*
* @author lengleng
*/
@Data
@AllArgsConstructor
public class MinioItem {
private String objectName;
private Date lastModified;
private String etag;
private Long size;
private String storageClass;
private Owner owner;
private String type;
public MinioItem(Item item) {
this.objectName = item.objectName();
this.lastModified = item.lastModified();
this.etag = item.etag();
this.size = (long) item.size();
this.storageClass = item.storageClass();
this.owner = item.owner();
this.type = item.isDir() ? "directory" : "file";
}
}
@@ -1,55 +0,0 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.minio.vo;
import io.minio.ObjectStat;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 存储对象的元数据
*
* @author lengleng
*/
@Data
@AllArgsConstructor
public class MinioObject {
private String bucketName;
private String name;
private Date createdTime;
private Long length;
private String etag;
private String contentType;
private Map<String, List<String>> httpHeaders;
public MinioObject(ObjectStat os) {
this.bucketName = os.bucketName();
this.name = os.name();
this.createdTime = os.createdTime();
this.length = os.length();
this.etag = os.etag();
this.contentType = os.contentType();
this.httpHeaders = os.httpHeaders();
}
}
@@ -1,2 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pigx.common.minio.MinioAutoConfiguration
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -9,7 +9,7 @@
<version>3.9.0-SNAPSHOT</version>
</parent>
<artifactId>pigx-common-aws</artifactId>
<artifactId>pigx-common-oss</artifactId>
<packaging>jar</packaging>
<description>pigx 文件系统依赖</description>
@@ -18,7 +18,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.543</version>
<version>${aws.version}</version>
</dependency>
</dependencies>
</project>
@@ -15,10 +15,10 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.aws;
package com.pig4cloud.pigx.common.oss;
import com.pig4cloud.pigx.common.aws.http.AwsEndpoint;
import com.pig4cloud.pigx.common.aws.service.AwsTemplate;
import com.pig4cloud.pigx.common.oss.http.OssEndpoint;
import com.pig4cloud.pigx.common.oss.service.OssTemplate;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -32,21 +32,21 @@ import org.springframework.context.annotation.Bean;
* @author 858695266
*/
@AllArgsConstructor
@EnableConfigurationProperties({AwsProperties.class})
public class AwsAutoConfiguration {
private final AwsProperties properties;
@EnableConfigurationProperties({OssProperties.class})
public class OssAutoConfiguration {
private final OssProperties properties;
@Bean
@ConditionalOnMissingBean(AwsTemplate.class)
@ConditionalOnMissingBean(OssTemplate.class)
@ConditionalOnProperty(name = "oss.endpoint")
AwsTemplate awsTemplate() {
return new AwsTemplate(properties);
OssTemplate awsTemplate() {
return new OssTemplate(properties);
}
@Bean
@ConditionalOnProperty(name = "oss.enable", havingValue = "true")
public AwsEndpoint awsEndpoint(AwsTemplate template) {
return new AwsEndpoint(template);
public OssEndpoint awsEndpoint(OssTemplate template) {
return new OssEndpoint(template);
}
}
@@ -15,7 +15,7 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.aws;
package com.pig4cloud.pigx.common.oss;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -27,19 +27,19 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author 858695266
* 配置文件添加:
* oss:
* enable: true
* endpoint: http://127.0.0.1:9000
* access-key: lengleng
* secret-key: lengleng
* bucket-name: lengleng
* region:
* custom-domain: https://oss.xxx.com/lengleng
*
* enable: true
* endpoint: http://127.0.0.1:9000
* access-key: lengleng
* secret-key: lengleng
* bucket-name: lengleng
* region:
* custom-domain: https://oss.xxx.com/lengleng
* <p>
* bucket 设置公共读权限
*/
@Data
@ConfigurationProperties(prefix = "oss")
public class AwsProperties {
public class OssProperties {
/**
* 对象存储服务的URL
*/
@@ -15,12 +15,12 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.aws.http;
package com.pig4cloud.pigx.common.oss.http;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import com.pig4cloud.pigx.common.aws.service.AwsTemplate;
import com.pig4cloud.pigx.common.oss.service.OssTemplate;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.http.HttpStatus;
@@ -42,8 +42,8 @@ import java.util.Map;
@RestController
@AllArgsConstructor
@RequestMapping("/aws")
public class AwsEndpoint {
private final AwsTemplate template;
public class OssEndpoint {
private final OssTemplate template;
/**
* Bucket Endpoints
@@ -15,7 +15,7 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.aws.service;
package com.pig4cloud.pigx.common.oss.service;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
@@ -27,7 +27,7 @@ import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.*;
import com.amazonaws.util.IOUtils;
import com.pig4cloud.pigx.common.aws.AwsProperties;
import com.pig4cloud.pigx.common.oss.OssProperties;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.InitializingBean;
@@ -48,8 +48,8 @@ import java.util.*;
* @since 1.0
*/
@RequiredArgsConstructor
public class AwsTemplate implements InitializingBean {
private final AwsProperties ossProperties;
public class OssTemplate implements InitializingBean {
private final OssProperties ossProperties;
private AmazonS3 amazonS3;
@@ -115,8 +115,8 @@ public class AwsTemplate implements InitializingBean {
* @param bucketName bucket名称
* @param objectName 文件名称
* @param expires 过期时间 <=7
* @see AmazonS3#generatePresignedUrl(String bucketName, String key, Date expiration)
* @return url
* @see AmazonS3#generatePresignedUrl(String bucketName, String key, Date expiration)
*/
@SneakyThrows
public String getObjectURL(String bucketName, String objectName, Integer expires) {
@@ -133,8 +133,8 @@ public class AwsTemplate implements InitializingBean {
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/GetObject">AWS API Documentation</a>
* @return 二进制流
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/GetObject">AWS API Documentation</a>
*/
@SneakyThrows
public InputStream getObject(String bucketName, String objectName) {
@@ -161,8 +161,8 @@ public class AwsTemplate implements InitializingBean {
* @param stream 文件流
* @param size 大小
* @param contextType 类型
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/PutObject">AWS API Documentation</a>
* @throws Exception
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/PutObject">AWS API Documentation</a>
*/
public PutObjectResult putObject(String bucketName, String objectName, InputStream stream, long size, String contextType) throws Exception {
// String fileName = getFileName(objectName);
@@ -181,8 +181,8 @@ public class AwsTemplate implements InitializingBean {
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/GetObject">AWS API Documentation</a>
* @throws Exception
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/GetObject">AWS API Documentation</a>
*/
public S3Object getObjectInfo(String bucketName, String objectName) throws Exception {
return amazonS3.getObject(bucketName, objectName);
@@ -193,8 +193,8 @@ public class AwsTemplate implements InitializingBean {
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/DeleteObject">AWS API Documentation</a>
* @throws Exception
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/DeleteObject">AWS API Documentation</a>
*/
public void removeObject(String bucketName, String objectName) throws Exception {
amazonS3.deleteObject(bucketName, objectName);
@@ -1,2 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pigx.common.aws.AwsAutoConfiguration
com.pig4cloud.pigx.common.oss.OssAutoConfiguration
+1 -2
View File
@@ -42,8 +42,7 @@
<module>pigx-common-gray</module>
<module>pigx-common-job</module>
<module>pigx-common-log</module>
<module>pigx-common-minio</module>
<module>pigx-common-aws</module>
<module>pigx-common-oss</module>
<module>pigx-common-security</module>
<module>pigx-common-sentinel</module>
<module>pigx-common-sequence</module>
+1 -1
View File
@@ -55,7 +55,7 @@
<!--文件系统-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-aws</artifactId>
<artifactId>pigx-common-oss</artifactId>
</dependency>
<!--注册中心客户端-->
<dependency>
@@ -24,10 +24,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.entity.SysFile;
import com.pig4cloud.pigx.admin.mapper.SysFileMapper;
import com.pig4cloud.pigx.admin.service.SysFileService;
import com.pig4cloud.pigx.common.aws.AwsProperties;
import com.pig4cloud.pigx.common.aws.service.AwsTemplate;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.oss.OssProperties;
import com.pig4cloud.pigx.common.oss.service.OssTemplate;
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
@@ -51,8 +50,8 @@ import java.util.Map;
@Service
@AllArgsConstructor
public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> implements SysFileService {
private final AwsTemplate minioTemplate;
private final AwsProperties awsProperties;
private final OssProperties ossProperties;
private final OssTemplate minioTemplate;
/**
@@ -65,12 +64,12 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
public R uploadFile(MultipartFile file) {
String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename());
Map<String, String> resultMap = new HashMap<>(4);
resultMap.put("bucketName", awsProperties.getBucketName());
resultMap.put("bucketName", ossProperties.getBucketName());
resultMap.put("fileName", fileName);
resultMap.put("url", String.format("/admin/sys-file/%s/%s", awsProperties.getBucketName(), fileName));
resultMap.put("url", String.format("/admin/sys-file/%s/%s", ossProperties.getBucketName(), fileName));
try {
minioTemplate.putObject(awsProperties.getBucketName(), fileName, file.getInputStream());
minioTemplate.putObject(ossProperties.getBucketName(), fileName, file.getInputStream());
//文件管理数据记录,收集管理追踪文件
fileLog(file, fileName);
} catch (Exception e) {
@@ -109,7 +108,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
@Transactional(rollbackFor = Exception.class)
public Boolean deleteFile(Long id) {
SysFile file = this.getById(id);
minioTemplate.removeObject(awsProperties.getBucketName(), file.getFileName());
minioTemplate.removeObject(ossProperties.getBucketName(), file.getFileName());
return this.removeById(id);
}
@@ -127,7 +126,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
sysFile.setOriginal(original);
sysFile.setFileSize(file.getSize());
sysFile.setType(FileUtil.extName(original));
sysFile.setBucketName(awsProperties.getBucketName());
sysFile.setBucketName(ossProperties.getBucketName());
sysFile.setCreateUser(SecurityUtils.getUser().getUsername());
this.save(sysFile);
}
-1
View File
@@ -48,7 +48,6 @@
<lcn.version>4.1.0</lcn.version>
<jasypt.version>2.1.1</jasypt.version>
<ttl.version>2.11.4</ttl.version>
<minio.version>6.0.13</minio.version>
<aws.version>1.11.543</aws.version>
<xxl.job.version>2.2.0</xxl.job.version>
<activiti.version>5.22.0</activiti.version>