|
@@ -4,14 +4,13 @@ import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.pavis.backend.slim.common.constant.Constant;
|
|
import com.pavis.backend.slim.common.constant.Constant;
|
|
import com.pavis.backend.slim.common.exception.UtilException;
|
|
import com.pavis.backend.slim.common.exception.UtilException;
|
|
-import io.minio.*;
|
|
|
|
-import io.minio.errors.ErrorResponseException;
|
|
|
|
-import io.minio.errors.InsufficientDataException;
|
|
|
|
-import io.minio.errors.InternalException;
|
|
|
|
-import io.minio.errors.InvalidResponseException;
|
|
|
|
|
|
+import io.minio.BucketExistsArgs;
|
|
|
|
+import io.minio.GetPresignedObjectUrlArgs;
|
|
|
|
+import io.minio.MakeBucketArgs;
|
|
|
|
+import io.minio.MinioClient;
|
|
|
|
+import io.minio.PutObjectArgs;
|
|
|
|
+import io.minio.RemoveObjectArgs;
|
|
import io.minio.errors.MinioException;
|
|
import io.minio.errors.MinioException;
|
|
-import io.minio.errors.ServerException;
|
|
|
|
-import io.minio.errors.XmlParserException;
|
|
|
|
import io.minio.http.Method;
|
|
import io.minio.http.Method;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -79,13 +78,24 @@ public class MinioStorage {
|
|
* @param file 文件input流
|
|
* @param file 文件input流
|
|
*/
|
|
*/
|
|
public void putObject(String key, MultipartFile file) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
|
public void putObject(String key, MultipartFile file) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
|
|
|
+ InputStream is = null;
|
|
try {
|
|
try {
|
|
// 1. 创建bucket
|
|
// 1. 创建bucket
|
|
createBucket(bucketName);
|
|
createBucket(bucketName);
|
|
// 2. 存储文件
|
|
// 2. 存储文件
|
|
- client.putObject(PutObjectArgs.builder().bucket(bucketName).object(key).stream(file.getInputStream(), file.getSize(), -1).build());
|
|
|
|
|
|
+ is = file.getInputStream();
|
|
|
|
+ client.putObject(PutObjectArgs.builder().bucket(bucketName).object(key).stream(is, file.getSize(), -1).build());
|
|
} catch (MinioException e) {
|
|
} catch (MinioException e) {
|
|
throw new UtilException(e.getMessage());
|
|
throw new UtilException(e.getMessage());
|
|
|
|
+ }finally {
|
|
|
|
+ if (is != null){
|
|
|
|
+ try {
|
|
|
|
+ is.close();
|
|
|
|
+ }catch (IOException ex){
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ log.info("上传文件至指定bucket或指定文件夹 ex:{}",ex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|