minio是什么?
是一個開源的對象存儲服務(wù),兼容 Amazon S3 云端存儲服務(wù),同時也支持本地磁盤、NAS、NFS、公有云存儲、分布式云存儲,非常適合用于存儲非結(jié)構(gòu)化數(shù)據(jù),比如:圖片、視頻、日志、備份、容器鏡像等。
對象大小最大能支持到 5TB。是一個非常輕量的服務(wù),可以很簡單的和其他應(yīng)用的結(jié)合。
快速入門示例-文件上傳
需要有存儲服務(wù)的三個參數(shù)才能連接到該服務(wù)。
| 參數(shù) | 說明 |
|---|---|
| Endpoint | 對象存儲服務(wù)的URL |
| Access Key | Access key就像用戶ID,可以唯一標(biāo)識你的賬戶。 |
| Secret Key | Secret key是你賬戶的密碼。 |
public class FileUploader {
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException, XmlPullParserException {
try {
// 使用MinIO服務(wù)的URL,端口,Access key和Secret key創(chuàng)建一個MinioClient對象
MinioClient minioClient = new MinioClient("https://play.min.io", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
// 檢查存儲桶是否已經(jīng)存在
boolean isExist = minioClient.bucketExists("asiatrip");
if(isExist) {
System.out.println("Bucket already exists.");
} else {
// 創(chuàng)建一個名為asiatrip的存儲桶,用于存儲照片的zip文件。
minioClient.makeBucket("asiatrip");
}
// 使用putObject上傳一個文件到存儲桶中。
minioClient.putObject("asiatrip","asiaphotos.zip", "/home/user/Photos/asiaphotos.zip");
System.out.println("/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.");
} catch(MinioException e) {
System.out.println("Error occurred: " + e);
}
}
}
API文檔