minio的go客戶端
阿新 • • 發佈:2020-12-18
技術標籤:學習實況
寫操作:
func MinioWrite(num int){
client, err := minio.New(
"127.0.0.1:9001",//地址
&minio.Options{
Creds: credentials.NewStaticV4("minio", "minio123", ""),//賬戶密碼
Secure: false,
},
)
if err != nil {
panic(err)
}
新建儲存桶,如果有則無需建立
//if err := client.MakeBucket(context.Background(), "image", minio.MakeBucketOptions{}); err != nil {
// panic(err)
//}
// 開啟本地的圖片
f, err := os.Open("ability.jpg")
if err != nil {
panic(err)
}
defer f.Close()
// 上傳圖片
if _, err := client.PutObject(
context.Background(),
"image",
fmt.Sprintf("test%v.jpg",num),
f,
-1,
minio.PutObjectOptions{ContentType: "image/jpeg" },
); err != nil {
panic(err)
}
}
刪除操作:
func MinioRemove(num int){
client, err := minio.New(
"127.0.0.1:9001",
&minio.Options{
Creds: credentials.NewStaticV4("minio", "minio123", ""),
Secure: false,
},
)
if err != nil {
panic(err)
}
// 刪除圖片
if err := client.RemoveObject(
context.Background(),
"image",
fmt.Sprintf("test%v.jpg",num),
minio.RemoveObjectOptions{},
); err != nil {
panic(err)
}
}