1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| package com.xuecheng.media;
import io.minio.*; import io.minio.errors.*; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.compress.utils.IOUtils; import org.junit.jupiter.api.Test;
import java.io.*; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException;
public class MinioTest { private MinioClient minioClient = MinioClient.builder() .endpoint("http://192.168.101.65:9001") //改成你的宿主机ip .credentials("minio", "minio123") .build();
@Test public void testCreate() throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException { ObjectWriteResponse file = minioClient.uploadObject( UploadObjectArgs.builder() .bucket("test") .filename("C:\\Users\\mumu\\Desktop\\1C6091EF9671978A9F1B6C6F8A3666FD.png") .object("1.png") .build() ); }
@Test public void testDelete() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException { minioClient.removeObject( RemoveObjectArgs.builder() .bucket("test") .object("12.msi") .build() ); }
@Test public void testGet() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException { InputStream inputStream = minioClient.getObject( GetObjectArgs.builder() .bucket("test") .object("1.png") .build() ); FileOutputStream outputStream = new FileOutputStream(new File("C:\\Users\\mumu\\Desktop\\2.png")); IOUtils.copy(inputStream, outputStream); }
}
|