| | |
| | | package com.ruoyi.device.hiksdk.util.minio; |
| | | |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.device.hiksdk.config.MinioClientSingleton; |
| | | import io.minio.*; |
| | | import io.minio.http.Method; |
| | |
| | | } |
| | | boolean exsit = exitsBucket(bucketName); |
| | | if (!exsit) { |
| | | log.error(bucketName + "-桶不存在"); |
| | | boolean bucket = createBucket(bucketName); |
| | | if(bucket) |
| | | { |
| | | log.info(bucketName + "-桶不存在,成功创建桶"); |
| | | } |
| | | } |
| | | //文件名 |
| | | String originalFilename = file.getOriginalFilename(); |
| | | //新的文件名 |
| | | String fileName = UUID.randomUUID().toString().replace("-", "") + originalFilename; |
| | | String fileName = IdUtils.fastSimpleUUID()+"_"+ originalFilename; |
| | | try { |
| | | InputStream inputStream = file.getInputStream(); |
| | | /*上传对象*/ |
| | |
| | | .builder() |
| | | .bucket(bucketName) |
| | | .object(fileName) |
| | | .method(Method.GET) |
| | | .build(); |
| | | return MinioClientSingleton.getMinioClient().getPresignedObjectUrl(getPresignedObjectUrlArgs); |
| | | String presignedObjectUrl = MinioClientSingleton.getMinioClient().getPresignedObjectUrl(getPresignedObjectUrlArgs); |
| | | String ObjectUrl = presignedObjectUrl.substring(0, presignedObjectUrl.indexOf("?")); |
| | | return ObjectUrl; |
| | | } catch (Exception ex) { |
| | | log.error("上传对象返回url异常:" + ex.getMessage()); |
| | | } |
| | |
| | | .builder() |
| | | .bucket(bucketName) |
| | | .object(objectName) |
| | | .method(Method.GET) |
| | | .build(); |
| | | return MinioClientSingleton.getMinioClient().getPresignedObjectUrl(getPresignedObjectUrlArgs); |
| | | } catch (Exception ex) { |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | *@描述 获取桶中所有对象 |
| | | *@参数 [bucketName] |