Minio S3 upload .jpg file to bucket

12 Views Asked by At

I need to create S3 bucket and upload .jpg files to created bucket.

  public void saveTest(){
    try {
      MinioClient minioClient = MinioClient.builder()
              .endpoint("http://localhost:9099")
              .credentials("minioadmin", "minioadmin")
              .build();

      boolean found =
              minioClient.bucketExists(BucketExistsArgs.builder().bucket("test").build());
      if (!found) {
   
        minioClient.makeBucket(MakeBucketArgs.builder().bucket("test").build());
      } else {
        System.out.println("Bucket 'test' already exists.");
      }

      FileInputStream stream = new FileInputStream("C:\\path\\picture.jpg");
      minioClient.putObject("test", "Resume.jpg", stream, (long) stream.available(), null, null, null);

     minioClient.putObject(PutObjectArgs
              .builder()
              .bucket("test")
              .object("Resume.jpg")
              .stream(new FileInputStream("C:\\path\\picture.jpg"), 1L, 5L * 1024 * 1024).build());
    } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
      System.out.println("Error occurred: " + e.getMessage());
      e.printStackTrace();
    }
  }

I dont have errors and the file appears in bucket, but i cant open it enter image description here

0

There are 0 best solutions below