Переглянути джерело

孙浩博,fixed:文件夹数据集上传功能

seamew 1 рік тому
батько
коміт
39ddf357fd

+ 13 - 0
src/main/java/io/renren/common/utils/MinIoUtils.java

@@ -202,6 +202,19 @@ public class MinIoUtils {
 
     }
 
+    /**
+     * Description 删除一个文件夹(包括其中的所有文件)
+     * @param bucketName 存储桶名称
+     * @param dirName 文件夹路径名/文件夹名
+     */
+    public static void deleteDir(String bucketName, String dirName) throws InvalidBucketNameException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, InsufficientDataException, IOException, XmlParserException, ErrorResponseException, InternalException {
+        Iterable<Result<Item>> myObjects = minioClient.listObjects(bucketName, dirName, true);
+        for (Result<Item> result : myObjects) {
+            Item item = result.get();
+            minioClient.removeObject(bucketName, item.objectName());
+        }
+    }
+
     /**
      * Description 批量删除指定前缀的文件
      * @param bucketName

+ 1 - 1
src/main/java/io/renren/modules/dataSet/enumeration/DataSetType.java

@@ -11,7 +11,7 @@ public enum DataSetType {
     STATIC_DATASET("dataset", ""),
     DYNAMIC_DATASET("dydataset", ""),
     FILE_DATASET("filedataset", "单文件"),
-    DIR_DATASET("dirdataset", "");
+    DIR_DATASET("dirdataset", "文件夹");
 
     private final String bucketName;
 

+ 12 - 0
src/main/java/io/renren/modules/dataSet/upload/UpLoadController.java

@@ -73,6 +73,18 @@ public class UpLoadController {
         return R.ok();
     }
 
+    @PostMapping("/uploadDir")
+    public R uploadDir(@RequestPart("files") MultipartFile[] files, @RequestParam("dataSet") String dataSetJson) throws Exception {
+        DataSet dataSet = new Gson().fromJson(dataSetJson, DataSet.class);
+        dataSet.setCreateTime(new Date());
+        dataSet.setCategoryId(categoryService.getByName(DataSetType.DIR_DATASET.getClassificationName()));
+        for (MultipartFile file : files) {
+            MinIoUtils.uploadMultipartFile(file, DataSetType.DIR_DATASET.getBucketName(), file.getOriginalFilename());
+        }
+        dataSetService.save(dataSet);
+        return R.ok();
+    }
+
 
     @RequestMapping("uploadcsv")
     public R uploadCSV(MultipartFile file) throws Exception {

+ 1 - 1
src/main/java/io/renren/modules/sys/controller/dataset/DataSetController.java

@@ -136,7 +136,7 @@ public class DataSetController {
             if (dataset.getCategoryId().equals(singleFile)) {
                 MinIoUtils.deleteFile(DataSetType.FILE_DATASET.getBucketName(), dataset.getDatasetName());
             } else if (dataset.getCategoryId().equals(dir)) {
-                MinIoUtils.deleteFile(DataSetType.DIR_DATASET.getBucketName(), dataset.getDatasetName());
+                MinIoUtils.deleteDir(DataSetType.DIR_DATASET.getBucketName(), dataset.getDatasetName());
             } else {
                 MinIoUtils.deleteFile(DataSetType.STATIC_DATASET.getBucketName(), dataset.getDatasetName()+".csv");
             }