springboot 定时删除minio某个桶里的数据

#每天2点删除2个小时前的所有数据
/*[秒] [分] [小时] [日] [月] [周] [年]*/
/*扫描临时文件定时删除*/
@Scheduled(cron = "0 0 2 * * ?")
public void scanBatchDel() {
    try {
        //1、查看临时文件夹是否存在,不存在创建一个
        String bucketName="temp";
        boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
        if (!found){
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
        }
        Iterable> list = minioClient.listObjects(
                ListObjectsArgs.builder().bucket(bucketName).build());
        Date date = DateUtil.beforeTime(2);
        List objects = new LinkedList<>();
        list.forEach(e->{
            try {
                ZonedDateTime zonedDateTime = e.get().lastModified();
                Date imgDate = Date.from(zonedDateTime.toInstant());
                if (imgDate.before(date)){
                   

你可能感兴趣的:(minio,spring,boot,java,后端)