|
@@ -2,6 +2,7 @@ package com.energy.manage.service.util;
|
|
|
|
|
|
|
|
|
import com.energy.manage.service.domain.dto.minio.ObjectItem;
|
|
|
+import com.xxl.job.core.util.IpUtil;
|
|
|
import io.minio.*;
|
|
|
import io.minio.messages.DeleteError;
|
|
|
import io.minio.messages.DeleteObject;
|
|
@@ -16,6 +17,7 @@ import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
@@ -41,6 +43,9 @@ public class MinioUtils {
|
|
|
@Value("${minio.endpoint}")
|
|
|
private String endpoint;
|
|
|
|
|
|
+ @Value("${minio.bucketPath}")
|
|
|
+ private String bucketPath;
|
|
|
+
|
|
|
/**
|
|
|
* description: 判断bucket是否存在,不存在则创建
|
|
|
*
|
|
@@ -172,7 +177,47 @@ public class MinioUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return this.endpoint+"/"+this.bucketName+"/"+fileName;
|
|
|
+ return this.bucketPath+"/"+this.bucketName+"/"+fileName;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * description: 单上传文件uploadRequest
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @return: java.lang.String
|
|
|
+ */
|
|
|
+ public String upload(MultipartFile file, HttpServletRequest request) {
|
|
|
+
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ String[] split = fileName.split("\\.");
|
|
|
+ if (split.length > 1) {
|
|
|
+ fileName = split[0] + "_" + System.currentTimeMillis() + "." + split[1];
|
|
|
+ } else {
|
|
|
+ fileName = fileName + System.currentTimeMillis();
|
|
|
+ }
|
|
|
+ InputStream in = null;
|
|
|
+ try {
|
|
|
+ in = file.getInputStream();
|
|
|
+ minioClient.putObject(PutObjectArgs.builder()
|
|
|
+ .bucket(bucketName)
|
|
|
+ .object(fileName)
|
|
|
+ .stream(in, in.available(), -1)
|
|
|
+ .contentType(file.getContentType())
|
|
|
+ .build()
|
|
|
+ );
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (in != null) {
|
|
|
+ try {
|
|
|
+ in.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String ip = IPUtils.getIpAddr(request);
|
|
|
+ return ip +"/"+this.bucketName+"/"+fileName;
|
|
|
}
|
|
|
|
|
|
/**
|