ÎļþÃû´Ó ard-work/src/main/java/com/ruoyi/device/hiksdk/util/minio/MinioUtils.java ÐÞ¸Ä |
| | |
| | | package com.ruoyi.device.hiksdk.util.minio; |
| | | package com.ruoyi.storage.minio.utils; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.device.hiksdk.config.MinioClientSingleton; |
| | | import io.minio.*; |
| | | import io.minio.http.Method; |
| | | import io.minio.messages.Bucket; |
| | | import io.minio.messages.DeleteError; |
| | | import io.minio.messages.DeleteObject; |
| | | import io.minio.messages.Item; |
| | | import io.minio.messages.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | public static boolean exitsBucket(String bucketName) { |
| | | boolean found = false; |
| | | try { |
| | | if(StringUtils.isEmpty(bucketName)) |
| | | { |
| | | if (StringUtils.isEmpty(bucketName)) { |
| | | return false; |
| | | } |
| | | BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder().bucket(bucketName).build(); |
| | | found = MinioClientSingleton.getMinioClient().bucketExists(bucketExistsArgs); |
| | | |
| | | } catch (Exception ex) { |
| | | log.error("minioå¤ææ¡¶åå¨å¼å¸¸ï¼", ex.getMessage()); |
| | | } |
| | |
| | | */ |
| | | public static boolean createBucket(String bucketName) { |
| | | try { |
| | | if(StringUtils.isEmpty(bucketName)) |
| | | { |
| | | if (StringUtils.isEmpty(bucketName)) { |
| | | return false; |
| | | } |
| | | /*å建桶*/ |
| | |
| | | .bucket(bucketName) |
| | | .config(sb) |
| | | .build(); |
| | | /*设置éç¥mqtt*/ |
| | | //设置mqttä¸»é¢ |
| | | NotificationConfiguration config = new NotificationConfiguration(); |
| | | List<QueueConfiguration> queueConfigurations = new ArrayList<>(); |
| | | QueueConfiguration queueConfiguration = new QueueConfiguration(); |
| | | queueConfiguration.setQueue("arn:minio:sqs::_:mqtt"); |
| | | |
| | | //设置äºä»¶ |
| | | List<EventType> events=new ArrayList<>(); |
| | | events.add(EventType.OBJECT_REMOVED_ANY); |
| | | events.add(EventType.OBJECT_CREATED_ANY); |
| | | queueConfiguration.setEvents(events); |
| | | |
| | | queueConfigurations.add(queueConfiguration); |
| | | config.setQueueConfigurationList(queueConfigurations); |
| | | SetBucketNotificationArgs setBucketNotificationArgs = SetBucketNotificationArgs.builder() |
| | | .bucket(bucketName) |
| | | .config(config).build(); |
| | | MinioClientSingleton.getMinioClient().setBucketPolicy(setBucketPolicyArgs); |
| | | MinioClientSingleton.getMinioClient().setBucketNotification(setBucketNotificationArgs); |
| | | |
| | | return true; |
| | | } catch (Exception ex) { |
| | | log.error("minioå建桶å¼å¸¸ï¼", ex.getMessage()); |
| | |
| | | } catch (Exception ex) { |
| | | log.error("minioçæå¤±æurlå¼å¸¸", ex.getMessage()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | createBucket(bucketName); |
| | | } |
| | | return url; |
| | |
| | | * @ä¿®æ¹äººåå
¶å®ä¿¡æ¯ |
| | | */ |
| | | public static String putObjectAndGetUrl(String bucketName, MultipartFile file) { |
| | | if(!exitsBucket(bucketName)) |
| | | { |
| | | if (!exitsBucket(bucketName)) { |
| | | createBucket(bucketName); |
| | | } |
| | | //夿æä»¶æ¯å¦ä¸ºç©º |
| | |
| | | * @ä¿®æ¹äººåå
¶å®ä¿¡æ¯ |
| | | */ |
| | | public static String putObjectAndGetUrl(String bucketName, String folder, MultipartFile file) { |
| | | if(!exitsBucket(bucketName)) |
| | | { |
| | | if (!exitsBucket(bucketName)) { |
| | | createBucket(bucketName); |
| | | } |
| | | //夿æä»¶æ¯å¦ä¸ºç©º |
| | |
| | | */ |
| | | public static boolean uploadObject(String bucketName, String objectName, InputStream stream, long size, String contextType) { |
| | | try { |
| | | if(!exitsBucket(bucketName)) |
| | | { |
| | | if (!exitsBucket(bucketName)) { |
| | | createBucket(bucketName); |
| | | } |
| | | PutObjectArgs putObjectArgs = PutObjectArgs.builder() |
| | |
| | | */ |
| | | public static boolean uploadObject(String bucketName, String objectName, File file, String contextType) { |
| | | try { |
| | | if(!exitsBucket(bucketName)) |
| | | { |
| | | if (!exitsBucket(bucketName)) { |
| | | createBucket(bucketName); |
| | | } |
| | | FileInputStream fileInputStream = new FileInputStream(file); |
| | |
| | | */ |
| | | public static boolean uploadObject(String bucketName, String objectName, MultipartFile multipartFile, String contextType) { |
| | | try { |
| | | if(!exitsBucket(bucketName)) |
| | | { |
| | | if (!exitsBucket(bucketName)) { |
| | | createBucket(bucketName); |
| | | } |
| | | InputStream inputStream = multipartFile.getInputStream(); |
| | |
| | | */ |
| | | public static boolean uploadObject(String bucketName, MultipartFile multipartFile, String contextType) { |
| | | try { |
| | | if(!exitsBucket(bucketName)) |
| | | { |
| | | if (!exitsBucket(bucketName)) { |
| | | createBucket(bucketName); |
| | | } |
| | | if (multipartFile == null) { |
| | |
| | | */ |
| | | public static boolean uploadObject(String bucketName, String objectName, String localFilePathName, String contextType) { |
| | | try { |
| | | if(!exitsBucket(bucketName)) |
| | | { |
| | | if (!exitsBucket(bucketName)) { |
| | | createBucket(bucketName); |
| | | } |
| | | File file = new File(localFilePathName); |