minio golang client使用

初始化

var (
  endpoint        = "127.0.0.1:8888"
  accessKeyID     = "YXU5IXETKKPX171K4Z6O"
  secretAccessKey = "ss8jOTCujaIYAPsgqq+cLXoTkw5xJ2BhzXwkMxES"
  useSSL          = false
  fileName = "C:/Users/Administrator/Desktop/testminio.mp4"
)

minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL) # 创建桶

上传文件

n, err := minioClient.FPutObject("test", "testminio.mp4", fileName, minio.PutObjectOptions{ContentType: "video/mpeg4"})

获得文件临时url

时间最少1秒,不能少于1秒

URL1, err := minioClient.PresignedGetObject("test", "817d043b.png", time.Second*24*60*60, make(url.Values))

net.url.URL ,err := minioClient.PresignedGetObject(桶,文件名称,时间,url)

获取桶内文件列表 

https://docs.minio.io/cn/golang-client-api-reference.html#ListObjects

objinfo := minioClient.ListObjects("test", "", true, make(chan struct{}))

  for obj := range objinfo {
    if obj.Err != nil {
      fmt.Println(obj.Err) return     }     fmt.Println(obj.Key)   }

获得桶列表

lists, err := minioClient.ListBuckets()

if err != nil {
  fmt.Println(err)
}

for _, list := range lists {
  fmt.Println(list.Name)
}

 

 

 

转载于:https://www.cnblogs.com/LC161616/p/10342200.html

你可能感兴趣的:(minio golang client使用)