洪城义警-正式版后台
zengh
2022-05-26 4310c19a73f960dfd79c90cfe960cf564b068f72
src/main/java/org/springblade/modules/depl/controller/DeplController.java
@@ -140,54 +140,13 @@
    *
    * @param file
    */
   @PostMapping("put-depl")
   public R put(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
      //填写你文件上传的地址以及相应信息
      String url = "http://web.byisf.com:9000";
      String access = "adminminio";
      String secret = "adminminio";
      String bucket = "jfpt";
      MinioClient minioClient =
         MinioClient.builder()
            .endpoint(url)
            .credentials(access, secret)
            .build();
      // 检查存储桶是否已经存在
      boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
      if (!isExist) {
         // 创建一个名为zip的存储桶,用于zip文件。
         minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
         minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
      }
      String fileName = file.getOriginalFilename();
      String newName = "upload/depl/" + UUID.randomUUID().toString().replaceAll("-", "")
         + fileName.substring(fileName.lastIndexOf("."));
      InputStream in = file.getInputStream();
      //创建头部信息
      Map<String, String> headers = new HashMap<>(1 << 2);
      //添加自定义内容类型
      headers.put("Content-Type", "application/octet-stream");
      //上传
      minioClient.putObject(
         PutObjectArgs.builder().bucket(bucket).object(newName).stream(
            in, in.available(), -1)
            .headers(headers)
            .build());
      in.close();
      String urls = "https://web.byisf.com/minio/jfpt/" + newName;
      return R.data(urls);
   }
//   @PostMapping("put-depl")
//   public R put(HttpServletResponse response, @RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
//      response.setHeader("Access-Control-Allow-Origin", "*");
//      response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
//      response.setHeader("Access-Control-Allow-Credentials","true");
//   public R put(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
//      //填写你文件上传的地址以及相应信息
//      String url = "http://223.82.109.183:2081";
//      String access = "zhbaadmin";
//      String secret = "zhbapassword";
//      String bucket = "zhba";
//      String url = "http://web.byisf.com:9000";
//      String access = "adminminio";
//      String secret = "adminminio";
//      String bucket = "jfpt";
//      MinioClient minioClient =
//         MinioClient.builder()
//            .endpoint(url)
@@ -215,10 +174,51 @@
//            .headers(headers)
//            .build());
//      in.close();
//      String urls = "http://223.82.109.183:2081/minio/zhba/" + newName;
//      String urls = "https://web.byisf.com/minio/jfpt/" + newName;
//      return R.data(urls);
//   }
   @PostMapping("put-depl")
   public R put(HttpServletResponse response, @RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
      response.setHeader("Access-Control-Allow-Origin", "*");
      response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
      response.setHeader("Access-Control-Allow-Credentials","true");
      //填写你文件上传的地址以及相应信息
      String url = "http://61.131.136.25:2081";
      String access = "zhbaadmin";
      String secret = "zhbapassword";
      String bucket = "zhba";
      MinioClient minioClient =
         MinioClient.builder()
            .endpoint(url)
            .credentials(access, secret)
            .build();
      // 检查存储桶是否已经存在
      boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
      if (!isExist) {
         // 创建一个名为zip的存储桶,用于zip文件。
         minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
         minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
      }
      String fileName = file.getOriginalFilename();
      String newName = "upload/depl/" + UUID.randomUUID().toString().replaceAll("-", "")
         + fileName.substring(fileName.lastIndexOf("."));
      InputStream in = file.getInputStream();
      //创建头部信息
      Map<String, String> headers = new HashMap<>(1 << 2);
      //添加自定义内容类型
      headers.put("Content-Type", "application/octet-stream");
      //上传
      minioClient.putObject(
         PutObjectArgs.builder().bucket(bucket).object(newName).stream(
            in, in.available(), -1)
            .headers(headers)
            .build());
      in.close();
      String urls = "http://61.131.136.25:2081/zhba/" + newName;
      return R.data(urls);
   }
   /**
    * 部署详情
    */