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
| import ( "context" "log" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" )
func main() { cli, err := minio.New("127.0.0.1:9000", &minio.Options{ Creds: credentials.NewStaticV4("admin", "strongpassword", ""), Secure: false, }) if err != nil { log.Fatal(err) }
ctx := context.Background() bucket := "media"
exists, _ := cli.BucketExists(ctx, bucket) if !exists { _ = cli.MakeBucket(ctx, bucket, minio.MakeBucketOptions{Region: "us-east-1"}) }
_, err = cli.FPutObject(ctx, bucket, "demo.jpg", "./demo.jpg", minio.PutObjectOptions{ ContentType: "image/jpeg", }) if err != nil { log.Fatal(err) }
url, _ := cli.PresignedGetObject(ctx, bucket, "demo.jpg", 3600, nil) log.Println(url) }
|