1# MinIO Go Client API Reference [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) 2 3## Initialize MinIO Client object. 4 5## MinIO 6 7```go 8package main 9 10import ( 11 "fmt" 12 13 "github.com/minio/minio-go/v6" 14) 15 16func main() { 17 // Use a secure connection. 18 ssl := true 19 20 // Initialize minio client object. 21 minioClient, err := minio.New("play.min.io", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", ssl) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26} 27``` 28 29## AWS S3 30 31```go 32package main 33 34import ( 35 "fmt" 36 37 "github.com/minio/minio-go/v6" 38) 39 40func main() { 41 // Use a secure connection. 42 ssl := true 43 44 // Initialize minio client object. 45 s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", ssl) 46 if err != nil { 47 fmt.Println(err) 48 return 49 } 50} 51``` 52 53| Bucket operations | Object operations | Encrypted Object operations | Presigned operations | Bucket Policy/Notification Operations | Client custom settings | 54| :--- | :--- | :--- | :--- | :--- | :--- | 55| [`MakeBucket`](#MakeBucket) | [`GetObject`](#GetObject) | [`GetObject`](#GetObject) | [`PresignedGetObject`](#PresignedGetObject) | [`SetBucketPolicy`](#SetBucketPolicy) | [`SetAppInfo`](#SetAppInfo) | 56| [`MakeBucketWithObjectLock`](#MakeBucketWithObjectLock) | [`PutObject`](#PutObject) | [`PutObject`](#PutObject) | [`PresignedPutObject`](#PresignedPutObject) | [`GetBucketPolicy`](#GetBucketPolicy) | [`SetCustomTransport`](#SetCustomTransport) | 57| [`ListBuckets`](#ListBuckets) | [`CopyObject`](#CopyObject) | [`CopyObject`](#CopyObject) | [`PresignedPostPolicy`](#PresignedPostPolicy) | [`SetBucketNotification`](#SetBucketNotification) | [`TraceOn`](#TraceOn) | 58| [`BucketExists`](#BucketExists) | [`StatObject`](#StatObject) | [`StatObject`](#StatObject) | | [`GetBucketNotification`](#GetBucketNotification) | [`TraceOff`](#TraceOff) | 59| [`RemoveBucket`](#RemoveBucket) | [`RemoveObject`](#RemoveObject) | | | [`RemoveAllBucketNotification`](#RemoveAllBucketNotification) | [`SetS3TransferAccelerate`](#SetS3TransferAccelerate) | 60| [`ListObjects`](#ListObjects) | [`RemoveObjects`](#RemoveObjects) | | | [`ListenBucketNotification`](#ListenBucketNotification) | | 61| [`ListObjectsV2`](#ListObjectsV2) | [`RemoveIncompleteUpload`](#RemoveIncompleteUpload) | | | [`SetBucketLifecycle`](#SetBucketLifecycle) | | 62| [`ListIncompleteUploads`](#ListIncompleteUploads) | [`FPutObject`](#FPutObject) | [`FPutObject`](#FPutObject) | | [`GetBucketLifecycle`](#GetBucketLifecycle) | | 63| | [`FGetObject`](#FGetObject) | [`FGetObject`](#FGetObject) | | [`SetBucketObjectLockConfig`](#SetBucketObjectLockConfig) | | 64| | [`ComposeObject`](#ComposeObject) | [`ComposeObject`](#ComposeObject) | | [`GetBucketObjectLockConfig`](#GetBucketObjectLockConfig) | | 65| | [`NewSourceInfo`](#NewSourceInfo) | [`NewSourceInfo`](#NewSourceInfo) | | [`EnableVersioning`](#EnableVersioning) | | 66| | [`NewDestinationInfo`](#NewDestinationInfo) | [`NewDestinationInfo`](#NewDestinationInfo) | | [`DisableVersioning`](#DisableVersioning) | | 67| | [`PutObjectWithContext`](#PutObjectWithContext) | [`PutObjectWithContext`](#PutObjectWithContext) | | [`SetBucketEncryption`](#SetBucketEncryption) | 68| | [`GetObjectWithContext`](#GetObjectWithContext) | [`GetObjectWithContext`](#GetObjectWithContext) | | [`GetBucketEncryption`](#GetBucketEncryption) | | 69| | [`FPutObjectWithContext`](#FPutObjectWithContext) | [`FPutObjectWithContext`](#FPutObjectWithContext) | | [`DeleteBucketEncryption`](#DeleteBucketEncryption) | 70| | [`FGetObjectWithContext`](#FGetObjectWithContext) | [`FGetObjectWithContext`](#FGetObjectWithContext) | | | 71| | [`RemoveObjectsWithContext`](#RemoveObjectsWithContext) | | | | 72| | [`RemoveObjectWithOptions`](#RemoveObjectWithOptions) | | | | 73| | [`PutObjectRetention`](#PutObjectRetention) | | | | 74| | [`GetObjectRetention`](#GetObjectRetention) | | | | 75| | [`PutObjectLegalHold`](#PutObjectLegalHold) | | | | 76| | [`GetObjectLegalHold`](#GetObjectLegalHold) | | | | 77| | [`SelectObjectContent`](#SelectObjectContent) | | 78| | [`PutObjectTagging`](#PutObjectTagging) | | 79| | [`PutObjectTaggingWithContext`](#PutObjectTaggingWithContext) | | 80| | [`GetObjectTagging`](#GetObjectTagging) | | 81| | [`GetObjectTaggingWithContext`](#GetObjectTaggingWithContext) | | 82| | [`RemoveObjectTagging`](#RemoveObjectTagging) | | 83| | [`RemoveObjectTaggingWithContext`](#RemoveObjectTaggingWithContext) | | 84 85## 1. Constructor 86<a name="MinIO"></a> 87 88### New(endpoint, accessKeyID, secretAccessKey string, ssl bool) (*Client, error) 89Initializes a new client object. 90 91__Parameters__ 92 93|Param |Type |Description | 94|:---|:---| :---| 95|`endpoint` | _string_ |S3 compatible object storage endpoint | 96|`accessKeyID` |_string_ |Access key for the object storage | 97|`secretAccessKey` | _string_ |Secret key for the object storage | 98|`ssl` | _bool_ | If 'true' API requests will be secure (HTTPS), and insecure (HTTP) otherwise | 99 100### NewWithRegion(endpoint, accessKeyID, secretAccessKey string, ssl bool, region string) (*Client, error) 101Initializes minio client, with region configured. Unlike New(), NewWithRegion avoids bucket-location lookup operations and it is slightly faster. Use this function when your application deals with a single region. 102 103### NewWithOptions(endpoint string, options *Options) (*Client, error) 104Initializes minio client with options configured. 105 106__Parameters__ 107 108|Param |Type |Description | 109|:---|:---| :---| 110|`endpoint` | _string_ |S3 compatible object storage endpoint | 111|`opts` |_minio.Options_ | Options for constructing a new client| 112 113__minio.Options__ 114 115|Field | Type | Description | 116|:--- |:--- | :--- | 117| `opts.Creds` | _*credentials.Credentials_ | Access Credentials| 118| `opts.Secure` | _bool_ | If 'true' API requests will be secure (HTTPS), and insecure (HTTP) otherwise | 119| `opts.Region` | _string_ | region | 120| `opts.BucketLookup` | _BucketLookupType_ | Bucket lookup type can be one of the following values | 121| | | _minio.BucketLookupDNS_ | 122| | | _minio.BucketLookupPath_ | 123| | | _minio.BucketLookupAuto_ | 124## 2. Bucket operations 125 126<a name="MakeBucket"></a> 127### MakeBucket(bucketName, location string) error 128Creates a new bucket. 129 130__Parameters__ 131 132| Param | Type | Description | 133|---|---|---| 134|`bucketName` | _string_ | Name of the bucket | 135| `location` | _string_ | Region where the bucket is to be created. Default value is us-east-1. Other valid values are listed below. Note: When used with minio server, use the region specified in its config file (defaults to us-east-1).| 136| | |us-east-1 | 137| | |us-east-2 | 138| | |us-west-1 | 139| | |us-west-2 | 140| | |ca-central-1 | 141| | |eu-west-1 | 142| | |eu-west-2 | 143| | |eu-west-3 | 144| | | eu-central-1| 145| | | eu-north-1| 146| | | ap-east-1| 147| | | ap-south-1| 148| | | ap-southeast-1| 149| | | ap-southeast-2| 150| | | ap-northeast-1| 151| | | ap-northeast-2| 152| | | ap-northeast-3| 153| | | me-south-1| 154| | | sa-east-1| 155| | | us-gov-west-1| 156| | | us-gov-east-1| 157| | | cn-north-1| 158| | | cn-northwest-1| 159 160 161__Example__ 162 163 164```go 165err = minioClient.MakeBucket("mybucket", "us-east-1") 166if err != nil { 167 fmt.Println(err) 168 return 169} 170fmt.Println("Successfully created mybucket.") 171``` 172 173<a name="MakeBucketWithObjectLock"></a> 174### MakeBucketWithObjectLock(bucketName, location string) error 175Creates a new bucket with object lock enabled. 176 177__Parameters__ 178 179| Param | Type | Description | 180|---|---|---| 181|`bucketName` | _string_ | Name of the bucket | 182| `location` | _string_ | Region where the bucket is to be created. Default value is us-east-1. Other valid values are listed below. Note: When used with minio server, use the region specified in its config file (defaults to us-east-1).| 183| | |us-east-1 | 184| | |us-west-1 | 185| | |us-west-2 | 186| | |eu-west-1 | 187| | | eu-central-1| 188| | | ap-southeast-1| 189| | | ap-northeast-1| 190| | | ap-southeast-2| 191| | | sa-east-1| 192 193 194__Example__ 195 196 197```go 198err = minioClient.MakeBucketWithObjectLock("mybucket", "us-east-1") 199if err != nil { 200 fmt.Println(err) 201 return 202} 203fmt.Println("Successfully created mybucket.") 204``` 205 206<a name="ListBuckets"></a> 207### ListBuckets() ([]BucketInfo, error) 208Lists all buckets. 209 210| Param | Type | Description | 211|---|---|---| 212|`bucketList` | _[]minio.BucketInfo_ | Lists of all buckets | 213 214 215__minio.BucketInfo__ 216 217| Field | Type | Description | 218|---|---|---| 219|`bucket.Name` | _string_ | Name of the bucket | 220|`bucket.CreationDate` | _time.Time_ | Date of bucket creation | 221 222 223__Example__ 224 225 226```go 227buckets, err := minioClient.ListBuckets() 228if err != nil { 229 fmt.Println(err) 230 return 231} 232for _, bucket := range buckets { 233 fmt.Println(bucket) 234} 235``` 236 237<a name="BucketExists"></a> 238### BucketExists(bucketName string) (found bool, err error) 239Checks if a bucket exists. 240 241__Parameters__ 242 243 244|Param |Type |Description | 245|:---|:---| :---| 246|`bucketName` | _string_ |Name of the bucket | 247 248 249__Return Values__ 250 251|Param |Type |Description | 252|:---|:---| :---| 253|`found` | _bool_ | Indicates whether bucket exists or not | 254|`err` | _error_ | Standard Error | 255 256 257__Example__ 258 259 260```go 261found, err := minioClient.BucketExists("mybucket") 262if err != nil { 263 fmt.Println(err) 264 return 265} 266if found { 267 fmt.Println("Bucket found") 268} 269``` 270 271<a name="RemoveBucket"></a> 272### RemoveBucket(bucketName string) error 273Removes a bucket, bucket should be empty to be successfully removed. 274 275__Parameters__ 276 277 278|Param |Type |Description | 279|:---|:---| :---| 280|`bucketName` | _string_ |Name of the bucket | 281 282__Example__ 283 284 285```go 286err = minioClient.RemoveBucket("mybucket") 287if err != nil { 288 fmt.Println(err) 289 return 290} 291``` 292 293<a name="ListObjects"></a> 294### ListObjects(bucketName, prefix string, recursive bool, doneCh chan struct{}) <-chan ObjectInfo 295Lists objects in a bucket. 296 297__Parameters__ 298 299 300|Param |Type |Description | 301|:---|:---| :---| 302|`bucketName` | _string_ |Name of the bucket | 303|`objectPrefix` |_string_ | Prefix of objects to be listed | 304|`recursive` | _bool_ |`true` indicates recursive style listing and `false` indicates directory style listing delimited by '/'. | 305|`doneCh` | _chan struct{}_ | A message on this channel ends the ListObjects iterator. | 306 307 308__Return Value__ 309 310|Param |Type |Description | 311|:---|:---| :---| 312|`objectInfo` | _chan minio.ObjectInfo_ |Read channel for all objects in the bucket, the object is of the format listed below: | 313 314__minio.ObjectInfo__ 315 316|Field |Type |Description | 317|:---|:---| :---| 318|`objectInfo.Key` | _string_ |Name of the object | 319|`objectInfo.Size` | _int64_ |Size of the object | 320|`objectInfo.ETag` | _string_ |MD5 checksum of the object | 321|`objectInfo.LastModified` | _time.Time_ |Time when object was last modified | 322 323 324```go 325// Create a done channel to control 'ListObjects' go routine. 326doneCh := make(chan struct{}) 327 328// Indicate to our routine to exit cleanly upon return. 329defer close(doneCh) 330 331isRecursive := true 332objectCh := minioClient.ListObjects("mybucket", "myprefix", isRecursive, doneCh) 333for object := range objectCh { 334 if object.Err != nil { 335 fmt.Println(object.Err) 336 return 337 } 338 fmt.Println(object) 339} 340``` 341 342 343<a name="ListObjectsV2"></a> 344### ListObjectsV2(bucketName, prefix string, recursive bool, doneCh chan struct{}) <-chan ObjectInfo 345Lists objects in a bucket using the recommended listing API v2 346 347__Parameters__ 348 349 350|Param |Type |Description | 351|:---|:---| :---| 352|`bucketName` | _string_ |Name of the bucket | 353| `objectPrefix` |_string_ | Prefix of objects to be listed | 354| `recursive` | _bool_ |`true` indicates recursive style listing and `false` indicates directory style listing delimited by '/'. | 355|`doneCh` | _chan struct{}_ | A message on this channel ends the ListObjectsV2 iterator. | 356 357 358__Return Value__ 359 360|Param |Type |Description | 361|:---|:---| :---| 362|`objectInfo` | _chan minio.ObjectInfo_ |Read channel for all the objects in the bucket, the object is of the format listed below: | 363 364 365```go 366// Create a done channel to control 'ListObjectsV2' go routine. 367doneCh := make(chan struct{}) 368 369// Indicate to our routine to exit cleanly upon return. 370defer close(doneCh) 371 372isRecursive := true 373objectCh := minioClient.ListObjectsV2("mybucket", "myprefix", isRecursive, doneCh) 374for object := range objectCh { 375 if object.Err != nil { 376 fmt.Println(object.Err) 377 return 378 } 379 fmt.Println(object) 380} 381``` 382 383<a name="ListIncompleteUploads"></a> 384### ListIncompleteUploads(bucketName, prefix string, recursive bool, doneCh chan struct{}) <- chan ObjectMultipartInfo 385Lists partially uploaded objects in a bucket. 386 387 388__Parameters__ 389 390 391|Param |Type |Description | 392|:---|:---| :---| 393|`bucketName` | _string_ |Name of the bucket | 394| `prefix` |_string_ | Prefix of objects that are partially uploaded | 395| `recursive` | _bool_ |`true` indicates recursive style listing and `false` indicates directory style listing delimited by '/'. | 396|`doneCh` | _chan struct{}_ | A message on this channel ends the ListenIncompleteUploads iterator. | 397 398 399__Return Value__ 400 401|Param |Type |Description | 402|:---|:---| :---| 403|`multiPartInfo` | _chan minio.ObjectMultipartInfo_ |Emits multipart objects of the format listed below: | 404 405__minio.ObjectMultipartInfo__ 406 407|Field |Type |Description | 408|:---|:---| :---| 409|`multiPartObjInfo.Key` | _string_ |Name of incompletely uploaded object | 410|`multiPartObjInfo.UploadID` | _string_ |Upload ID of incompletely uploaded object | 411|`multiPartObjInfo.Size` | _int64_ |Size of incompletely uploaded object | 412 413__Example__ 414 415 416```go 417// Create a done channel to control 'ListObjects' go routine. 418doneCh := make(chan struct{}) 419 420// Indicate to our routine to exit cleanly upon return. 421defer close(doneCh) 422 423isRecursive := true // Recursively list everything at 'myprefix' 424multiPartObjectCh := minioClient.ListIncompleteUploads("mybucket", "myprefix", isRecursive, doneCh) 425for multiPartObject := range multiPartObjectCh { 426 if multiPartObject.Err != nil { 427 fmt.Println(multiPartObject.Err) 428 return 429 } 430 fmt.Println(multiPartObject) 431} 432``` 433 434## 3. Object operations 435 436<a name="GetObject"></a> 437### GetObject(bucketName, objectName string, opts GetObjectOptions) (*Object, error) 438Returns a stream of the object data. Most of the common errors occur when reading the stream. 439 440 441__Parameters__ 442 443 444|Param |Type |Description | 445|:---|:---| :---| 446|`bucketName` | _string_ |Name of the bucket | 447|`objectName` | _string_ |Name of the object | 448|`opts` | _minio.GetObjectOptions_ | Options for GET requests specifying additional options like encryption, If-Match | 449 450 451__minio.GetObjectOptions__ 452 453|Field | Type | Description | 454|:---|:---|:---| 455| `opts.ServerSideEncryption` | _encrypt.ServerSide_ | Interface provided by `encrypt` package to specify server-side-encryption. (For more information see https://godoc.org/github.com/minio/minio-go/v6) | 456 457__Return Value__ 458 459 460|Param |Type |Description | 461|:---|:---| :---| 462|`object` | _*minio.Object_ |_minio.Object_ represents object reader. It implements io.Reader, io.Seeker, io.ReaderAt and io.Closer interfaces. | 463 464 465__Example__ 466 467 468```go 469object, err := minioClient.GetObject("mybucket", "myobject", minio.GetObjectOptions{}) 470if err != nil { 471 fmt.Println(err) 472 return 473} 474localFile, err := os.Create("/tmp/local-file.jpg") 475if err != nil { 476 fmt.Println(err) 477 return 478} 479if _, err = io.Copy(localFile, object); err != nil { 480 fmt.Println(err) 481 return 482} 483``` 484 485<a name="FGetObject"></a> 486### FGetObject(bucketName, objectName, filePath string, opts GetObjectOptions) error 487Downloads and saves the object as a file in the local filesystem. 488 489__Parameters__ 490 491 492|Param |Type |Description | 493|:---|:---| :---| 494|`bucketName` | _string_ |Name of the bucket | 495|`objectName` | _string_ |Name of the object | 496|`filePath` | _string_ |Path to download object to | 497|`opts` | _minio.GetObjectOptions_ | Options for GET requests specifying additional options like encryption, If-Match | 498 499 500__Example__ 501 502 503```go 504err = minioClient.FGetObject("mybucket", "myobject", "/tmp/myobject", minio.GetObjectOptions{}) 505if err != nil { 506 fmt.Println(err) 507 return 508} 509``` 510<a name="GetObjectWithContext"></a> 511### GetObjectWithContext(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (*Object, error) 512Identical to GetObject operation, but accepts a context for request cancellation. 513 514__Parameters__ 515 516 517|Param |Type |Description | 518|:---|:---| :---| 519|`ctx` | _context.Context_ |Request context | 520|`bucketName` | _string_ |Name of the bucket | 521|`objectName` | _string_ |Name of the object | 522|`opts` | _minio.GetObjectOptions_ | Options for GET requests specifying additional options like encryption, If-Match | 523 524 525__Return Value__ 526 527 528|Param |Type |Description | 529|:---|:---| :---| 530|`object` | _*minio.Object_ |_minio.Object_ represents object reader. It implements io.Reader, io.Seeker, io.ReaderAt and io.Closer interfaces. | 531 532 533__Example__ 534 535 536```go 537ctx, cancel := context.WithTimeout(context.Background(), 100 * time.Second) 538defer cancel() 539 540object, err := minioClient.GetObjectWithContext(ctx, "mybucket", "myobject", minio.GetObjectOptions{}) 541if err != nil { 542 fmt.Println(err) 543 return 544} 545 546localFile, err := os.Create("/tmp/local-file.jpg") 547if err != nil { 548 fmt.Println(err) 549 return 550} 551 552if _, err = io.Copy(localFile, object); err != nil { 553 fmt.Println(err) 554 return 555} 556``` 557 558<a name="FGetObjectWithContext"></a> 559### FGetObjectWithContext(ctx context.Context, bucketName, objectName, filePath string, opts GetObjectOptions) error 560Identical to FGetObject operation, but allows request cancellation. 561 562__Parameters__ 563 564 565|Param |Type |Description | 566|:---|:---| :---| 567|`ctx` | _context.Context_ |Request context | 568|`bucketName` | _string_ |Name of the bucket | 569|`objectName` | _string_ |Name of the object | 570|`filePath` | _string_ |Path to download object to | 571|`opts` | _minio.GetObjectOptions_ | Options for GET requests specifying additional options like encryption, If-Match | 572 573 574__Example__ 575 576 577```go 578ctx, cancel := context.WithTimeout(context.Background(), 100 * time.Second) 579defer cancel() 580 581err = minioClient.FGetObjectWithContext(ctx, "mybucket", "myobject", "/tmp/myobject", minio.GetObjectOptions{}) 582if err != nil { 583 fmt.Println(err) 584 return 585} 586``` 587 588<a name="PutObject"></a> 589### PutObject(bucketName, objectName string, reader io.Reader, objectSize int64,opts PutObjectOptions) (n int, err error) 590Uploads objects that are less than 128MiB in a single PUT operation. For objects that are greater than 128MiB in size, PutObject seamlessly uploads the object as parts of 128MiB or more depending on the actual file size. The max upload size for an object is 5TB. 591 592__Parameters__ 593 594 595|Param |Type |Description | 596|:---|:---| :---| 597|`bucketName` | _string_ |Name of the bucket | 598|`objectName` | _string_ |Name of the object | 599|`reader` | _io.Reader_ |Any Go type that implements io.Reader | 600|`objectSize`| _int64_ |Size of the object being uploaded. Pass -1 if stream size is unknown | 601|`opts` | _minio.PutObjectOptions_ | Allows user to set optional custom metadata, content headers, encryption keys and number of threads for multipart upload operation. | 602 603__minio.PutObjectOptions__ 604 605|Field | Type | Description | 606|:--- |:--- | :--- | 607| `opts.UserMetadata` | _map[string]string_ | Map of user metadata| 608| `opts.UserTags` | _map[string]string_ | Map of user object tags | 609| `opts.Progress` | _io.Reader_ | Reader to fetch progress of an upload | 610| `opts.ContentType` | _string_ | Content type of object, e.g "application/text" | 611| `opts.ContentEncoding` | _string_ | Content encoding of object, e.g "gzip" | 612| `opts.ContentDisposition` | _string_ | Content disposition of object, "inline" | 613| `opts.ContentLanguage` | _string_ | Content language of object, e.g "French" | 614| `opts.CacheControl` | _string_ | Used to specify directives for caching mechanisms in both requests and responses e.g "max-age=600"| 615| `opts.Mode` | _*minio.RetentionMode_ | Retention mode to be set, e.g "COMPLIANCE" | 616| `opts.RetainUntilDate` | _*time.Time_ | Time until which the retention applied is valid| 617| `opts.ServerSideEncryption` | _encrypt.ServerSide_ | Interface provided by `encrypt` package to specify server-side-encryption. (For more information see https://godoc.org/github.com/minio/minio-go/v6) | 618| `opts.StorageClass` | _string_ | Specify storage class for the object. Supported values for MinIO server are `REDUCED_REDUNDANCY` and `STANDARD` | 619| `opts.WebsiteRedirectLocation` | _string_ | Specify a redirect for the object, to another object in the same bucket or to a external URL. | 620 621__Example__ 622 623 624```go 625file, err := os.Open("my-testfile") 626if err != nil { 627 fmt.Println(err) 628 return 629} 630defer file.Close() 631 632fileStat, err := file.Stat() 633if err != nil { 634 fmt.Println(err) 635 return 636} 637 638n, err := minioClient.PutObject("mybucket", "myobject", file, fileStat.Size(), minio.PutObjectOptions{ContentType:"application/octet-stream"}) 639if err != nil { 640 fmt.Println(err) 641 return 642} 643fmt.Println("Successfully uploaded bytes: ", n) 644``` 645 646API methods PutObjectWithSize, PutObjectWithMetadata, PutObjectStreaming, and PutObjectWithProgress available in minio-go SDK release v3.0.3 are replaced by the new PutObject call variant that accepts a pointer to PutObjectOptions struct. 647 648<a name="PutObjectWithContext"></a> 649### PutObjectWithContext(ctx context.Context, bucketName, objectName string, reader io.Reader, objectSize int64, opts PutObjectOptions) (n int, err error) 650Identical to PutObject operation, but allows request cancellation. 651 652__Parameters__ 653 654 655|Param |Type |Description | 656|:---|:---| :---| 657|`ctx` | _context.Context_ |Request context | 658|`bucketName` | _string_ |Name of the bucket | 659|`objectName` | _string_ |Name of the object | 660|`reader` | _io.Reader_ |Any Go type that implements io.Reader | 661|`objectSize`| _int64_ | size of the object being uploaded. Pass -1 if stream size is unknown | 662|`opts` | _minio.PutObjectOptions_ |Pointer to struct that allows user to set optional custom metadata, content-type, content-encoding, content-disposition, content-language and cache-control headers, pass encryption module for encrypting objects, and optionally configure number of threads for multipart put operation. | 663 664 665__Example__ 666 667 668```go 669ctx, cancel := context.WithTimeout(context.Background(), 10 * time.Second) 670defer cancel() 671 672file, err := os.Open("my-testfile") 673if err != nil { 674 fmt.Println(err) 675 return 676} 677defer file.Close() 678 679fileStat, err := file.Stat() 680if err != nil { 681 fmt.Println(err) 682 return 683} 684 685n, err := minioClient.PutObjectWithContext(ctx, "my-bucketname", "my-objectname", file, fileStat.Size(), minio.PutObjectOptions{ 686 ContentType: "application/octet-stream", 687}) 688if err != nil { 689 fmt.Println(err) 690 return 691} 692fmt.Println("Successfully uploaded bytes: ", n) 693``` 694 695<a name="CopyObject"></a> 696### CopyObject(dst DestinationInfo, src SourceInfo) error 697Create or replace an object through server-side copying of an existing object. It supports conditional copying, copying a part of an object and server-side encryption of destination and decryption of source. See the `SourceInfo` and `DestinationInfo` types for further details. 698 699To copy multiple source objects into a single destination object see the `ComposeObject` API. 700 701__Parameters__ 702 703 704|Param |Type |Description | 705|:---|:---| :---| 706|`dst` | _minio.DestinationInfo_ |Argument describing the destination object | 707|`src` | _minio.SourceInfo_ |Argument describing the source object | 708 709 710__Example__ 711 712 713```go 714// Use-case 1: Simple copy object with no conditions. 715// Source object 716src := minio.NewSourceInfo("my-sourcebucketname", "my-sourceobjectname", nil) 717 718// Destination object 719dst, err := minio.NewDestinationInfo("my-bucketname", "my-objectname", nil, nil) 720if err != nil { 721 fmt.Println(err) 722 return 723} 724 725// Copy object call 726err = minioClient.CopyObject(dst, src) 727if err != nil { 728 fmt.Println(err) 729 return 730} 731``` 732 733```go 734// Use-case 2: 735// Copy object with copy-conditions, and copying only part of the source object. 736// 1. that matches a given ETag 737// 2. and modified after 1st April 2014 738// 3. but unmodified since 23rd April 2014 739// 4. copy only first 1MiB of object. 740 741// Source object 742src := minio.NewSourceInfo("my-sourcebucketname", "my-sourceobjectname", nil) 743 744// Set matching ETag condition, copy object which matches the following ETag. 745src.SetMatchETagCond("31624deb84149d2f8ef9c385918b653a") 746 747// Set modified condition, copy object modified since 2014 April 1. 748src.SetModifiedSinceCond(time.Date(2014, time.April, 1, 0, 0, 0, 0, time.UTC)) 749 750// Set unmodified condition, copy object unmodified since 2014 April 23. 751src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 23, 0, 0, 0, 0, time.UTC)) 752 753// Set copy-range of only first 1MiB of file. 754src.SetRange(0, 1024*1024-1) 755 756// Destination object 757dst, err := minio.NewDestinationInfo("my-bucketname", "my-objectname", nil, nil) 758if err != nil { 759 fmt.Println(err) 760 return 761} 762 763// Copy object call 764err = minioClient.CopyObject(dst, src) 765if err != nil { 766 fmt.Println(err) 767 return 768} 769``` 770 771<a name="ComposeObject"></a> 772### ComposeObject(dst minio.DestinationInfo, srcs []minio.SourceInfo) error 773Create an object by concatenating a list of source objects using server-side copying. 774 775__Parameters__ 776 777 778|Param |Type |Description | 779|:---|:---|:---| 780|`dst` | _minio.DestinationInfo_ |Struct with info about the object to be created. | 781|`srcs` | _[]minio.SourceInfo_ |Slice of struct with info about source objects to be concatenated in order. | 782 783 784__Example__ 785 786 787```go 788// Prepare source decryption key (here we assume same key to 789// decrypt all source objects.) 790sseSrc := encrypt.DefaultPBKDF([]byte("password"), []byte("salt")) 791 792// Source objects to concatenate. We also specify decryption 793// key for each 794src1 := minio.NewSourceInfo("bucket1", "object1", sseSrc) 795src1.SetMatchETagCond("31624deb84149d2f8ef9c385918b653a") 796 797src2 := minio.NewSourceInfo("bucket2", "object2", sseSrc) 798src2.SetMatchETagCond("f8ef9c385918b653a31624deb84149d2") 799 800src3 := minio.NewSourceInfo("bucket3", "object3", sseSrc) 801src3.SetMatchETagCond("5918b653a31624deb84149d2f8ef9c38") 802 803// Create slice of sources. 804srcs := []minio.SourceInfo{src1, src2, src3} 805 806// Prepare destination encryption key 807sseDst := encrypt.DefaultPBKDF([]byte("new-password"), []byte("new-salt")) 808 809// Create destination info 810dst, err := minio.NewDestinationInfo("bucket", "object", sseDst, nil) 811if err != nil { 812 fmt.Println(err) 813 return 814} 815 816// Compose object call by concatenating multiple source files. 817err = minioClient.ComposeObject(dst, srcs) 818if err != nil { 819 fmt.Println(err) 820 return 821} 822 823fmt.Println("Composed object successfully.") 824``` 825 826<a name="NewSourceInfo"></a> 827### NewSourceInfo(bucket, object string, decryptSSEC *SSEInfo) SourceInfo 828Construct a `SourceInfo` object that can be used as the source for server-side copying operations like `CopyObject` and `ComposeObject`. This object can be used to set copy-conditions on the source. 829 830__Parameters__ 831 832| Param | Type | Description | 833| :--- | :--- | :--- | 834| `bucket` | _string_ | Name of the source bucket | 835| `object` | _string_ | Name of the source object | 836| `sse` | _*encrypt.ServerSide_ | Interface provided by `encrypt` package to specify server-side-encryption. (For more information see https://godoc.org/github.com/minio/minio-go/v6) | 837 838__Example__ 839 840```go 841// No decryption parameter. 842src := minio.NewSourceInfo("bucket", "object", nil) 843 844// Destination object 845dst, err := minio.NewDestinationInfo("my-bucketname", "my-objectname", nil, nil) 846if err != nil { 847 fmt.Println(err) 848 return 849} 850 851// Copy object call 852err = minioClient.CopyObject(dst, src) 853if err != nil { 854 fmt.Println(err) 855 return 856} 857``` 858 859```go 860// With decryption parameter. 861sseSrc := encrypt.DefaultPBKDF([]byte("password"), []byte("salt")) 862src := minio.NewSourceInfo("bucket", "object", sseSrc) 863 864// Destination object 865dst, err := minio.NewDestinationInfo("my-bucketname", "my-objectname", nil, nil) 866if err != nil { 867 fmt.Println(err) 868 return 869} 870 871// Copy object call 872err = minioClient.CopyObject(dst, src) 873if err != nil { 874 fmt.Println(err) 875 return 876} 877``` 878 879<a name="NewDestinationInfo"></a> 880### NewDestinationInfo(bucket, object string, encryptSSEC *SSEInfo, userMeta map[string]string) (DestinationInfo, error) 881Construct a `DestinationInfo` object that can be used as the destination object for server-side copying operations like `CopyObject` and `ComposeObject`. 882 883__Parameters__ 884 885| Param | Type | Description | 886| :--- | :--- | :--- | 887| `bucket` | _string_ | Name of the destination bucket | 888| `object` | _string_ | Name of the destination object | 889| `sse` | _*encrypt.ServerSide_ | Interface provided by `encrypt` package to specify server-side-encryption. (For more information see https://godoc.org/github.com/minio/minio-go/v6) | | 890| `userMeta` | _map[string]string_ | User metadata to be set on the destination. If nil, with only one source, user-metadata is copied from source. | 891 892__Example__ 893 894```go 895// No encryption parameter. 896src := minio.NewSourceInfo("bucket", "object", nil) 897dst, err := minio.NewDestinationInfo("bucket", "object", nil, nil) 898if err != nil { 899 fmt.Println(err) 900 return 901} 902 903// Copy object call 904err = minioClient.CopyObject(dst, src) 905if err != nil { 906 fmt.Println(err) 907 return 908} 909``` 910 911```go 912src := minio.NewSourceInfo("bucket", "object", nil) 913 914// With encryption parameter. 915sseDst := encrypt.DefaultPBKDF([]byte("password"), []byte("salt")) 916dst, err := minio.NewDestinationInfo("bucket", "object", sseDst, nil) 917if err != nil { 918 fmt.Println(err) 919 return 920} 921 922// Copy object call 923err = minioClient.CopyObject(dst, src) 924if err != nil { 925 fmt.Println(err) 926 return 927} 928``` 929 930<a name="NewDestinationInfoWithOptions"></a> 931### NewDestinationInfoWithOptions(bucket, object string, destOpts DestInfoOptions) (DestinationInfo, error) 932Construct a `DestinationInfo` object that can be used as the destination object for server-side copying operations like `CopyObject` and `ComposeObject`. 933 934__Parameters__ 935 936| Param | Type | Description | 937| :--- | :--- | :--- | 938| `bucket` | _string_ | Name of the destination bucket | 939| `object` | _string_ | Name of the destination object | 940| `destOpts` | _minio.DestInfoOptions_ | Pointer to struct that allows user to set optional custom metadata, user tags, and server side encryption parameters. | 941 942__Example__ 943 944```go 945// No encryption parameter. 946src := minio.NewSourceInfo("bucket", "object", nil) 947tags := map[string]string{ 948 "Tag1": "Value1", 949 "Tag2": "Value2", 950} 951dst, err := minio.NewDestinationInfoWithOptions("bucket", "object", minio.DestInfoOptions{ 952 UserTags: tags, ReplaceTags: true, 953}) 954if err != nil { 955 fmt.Println(err) 956 return 957} 958 959// Copy object call 960err = minioClient.CopyObject(dst, src) 961if err != nil { 962 fmt.Println(err) 963 return 964} 965``` 966 967```go 968src := minio.NewSourceInfo("bucket", "object", nil) 969 970// With encryption parameter. 971sseDst := encrypt.DefaultPBKDF([]byte("password"), []byte("salt")) 972tags := map[string]string{ 973 "Tag1": "Value1", 974 "Tag2": "Value2", 975} 976dst, err := minio.NewDestinationInfoWithOptions("bucket", "object", minio.DestInfoOptions{ 977 Encryption: sseDst, UserTags: tags, ReplaceTags: true, 978}) 979if err != nil { 980 fmt.Println(err) 981 return 982} 983 984// Copy object call 985err = minioClient.CopyObject(dst, src) 986if err != nil { 987 fmt.Println(err) 988 return 989} 990``` 991 992<a name="FPutObject"></a> 993### FPutObject(bucketName, objectName, filePath, opts PutObjectOptions) (length int64, err error) 994Uploads contents from a file to objectName. 995 996FPutObject uploads objects that are less than 128MiB in a single PUT operation. For objects that are greater than the 128MiB in size, FPutObject seamlessly uploads the object in chunks of 128MiB or more depending on the actual file size. The max upload size for an object is 5TB. 997 998__Parameters__ 999 1000 1001|Param |Type |Description | 1002|:---|:---| :---| 1003|`bucketName` | _string_ |Name of the bucket | 1004|`objectName` | _string_ |Name of the object | 1005|`filePath` | _string_ |Path to file to be uploaded | 1006|`opts` | _minio.PutObjectOptions_ |Pointer to struct that allows user to set optional custom metadata, content-type, content-encoding, content-disposition, content-language and cache-control headers, pass encryption module for encrypting objects, and optionally configure number of threads for multipart put operation. | 1007 1008 1009__Example__ 1010 1011 1012```go 1013n, err := minioClient.FPutObject("my-bucketname", "my-objectname", "my-filename.csv", minio.PutObjectOptions{ 1014 ContentType: "application/csv", 1015}); 1016if err != nil { 1017 fmt.Println(err) 1018 return 1019} 1020fmt.Println("Successfully uploaded bytes: ", n) 1021``` 1022 1023<a name="FPutObjectWithContext"></a> 1024### FPutObjectWithContext(ctx context.Context, bucketName, objectName, filePath, opts PutObjectOptions) (length int64, err error) 1025Identical to FPutObject operation, but allows request cancellation. 1026 1027__Parameters__ 1028 1029 1030|Param |Type |Description | 1031|:---|:---| :---| 1032|`ctx` | _context.Context_ |Request context | 1033|`bucketName` | _string_ |Name of the bucket | 1034|`objectName` | _string_ |Name of the object | 1035|`filePath` | _string_ |Path to file to be uploaded | 1036|`opts` | _minio.PutObjectOptions_ |Pointer to struct that allows user to set optional custom metadata, content-type, content-encoding,content-disposition and cache-control headers, pass encryption module for encrypting objects, and optionally configure number of threads for multipart put operation. | 1037 1038__Example__ 1039 1040 1041```go 1042ctx, cancel := context.WithTimeout(context.Background(), 100 * time.Second) 1043defer cancel() 1044 1045n, err := minioClient.FPutObjectWithContext(ctx, "mybucket", "myobject.csv", "/tmp/otherobject.csv", minio.PutObjectOptions{ContentType:"application/csv"}) 1046if err != nil { 1047 fmt.Println(err) 1048 return 1049} 1050fmt.Println("Successfully uploaded bytes: ", n) 1051``` 1052 1053<a name="StatObject"></a> 1054### StatObject(bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) 1055Fetch metadata of an object. 1056 1057__Parameters__ 1058 1059 1060|Param |Type |Description | 1061|:---|:---| :---| 1062|`bucketName` | _string_ |Name of the bucket | 1063|`objectName` | _string_ |Name of the object | 1064|`opts` | _minio.StatObjectOptions_ | Options for GET info/stat requests specifying additional options like encryption, If-Match | 1065 1066 1067__Return Value__ 1068 1069|Param |Type |Description | 1070|:---|:---| :---| 1071|`objInfo` | _minio.ObjectInfo_ |Object stat information | 1072 1073 1074__minio.ObjectInfo__ 1075 1076|Field |Type |Description | 1077|:---|:---| :---| 1078|`objInfo.LastModified` | _time.Time_ |Time when object was last modified | 1079|`objInfo.ETag` | _string_ |MD5 checksum of the object| 1080|`objInfo.ContentType` | _string_ |Content type of the object| 1081|`objInfo.Size` | _int64_ |Size of the object| 1082 1083 1084__Example__ 1085 1086 1087```go 1088objInfo, err := minioClient.StatObject("mybucket", "myobject", minio.StatObjectOptions{}) 1089if err != nil { 1090 fmt.Println(err) 1091 return 1092} 1093fmt.Println(objInfo) 1094``` 1095 1096<a name="RemoveObject"></a> 1097### RemoveObject(bucketName, objectName string) error 1098Removes an object. 1099 1100__Parameters__ 1101 1102 1103|Param |Type |Description | 1104|:---|:---| :---| 1105|`bucketName` | _string_ |Name of the bucket | 1106|`objectName` | _string_ |Name of the object | 1107 1108 1109```go 1110err = minioClient.RemoveObject("mybucket", "myobject") 1111if err != nil { 1112 fmt.Println(err) 1113 return 1114} 1115``` 1116 1117<a name="RemoveObjects"></a> 1118### RemoveObjects(bucketName string, objectsCh chan string) (errorCh <-chan RemoveObjectError) 1119Removes a list of objects obtained from an input channel. The call sends a delete request to the server up to 1000 objects at a time. The errors observed are sent over the error channel. 1120 1121__Parameters__ 1122 1123|Param |Type |Description | 1124|:---|:---| :---| 1125|`bucketName` | _string_ |Name of the bucket | 1126|`objectsCh` | _chan string_ | Channel of objects to be removed | 1127 1128 1129__Return Values__ 1130 1131|Param |Type |Description | 1132|:---|:---| :---| 1133|`errorCh` | _<-chan minio.RemoveObjectError_ | Receive-only channel of errors observed during deletion. | 1134 1135 1136```go 1137objectsCh := make(chan string) 1138 1139// Send object names that are needed to be removed to objectsCh 1140go func() { 1141 defer close(objectsCh) 1142 // List all objects from a bucket-name with a matching prefix. 1143 for object := range minioClient.ListObjects("my-bucketname", "my-prefixname", true, nil) { 1144 if object.Err != nil { 1145 log.Fatalln(object.Err) 1146 } 1147 objectsCh <- object.Key 1148 } 1149}() 1150 1151for rErr := range minioClient.RemoveObjects("mybucket", objectsCh) { 1152 fmt.Println("Error detected during deletion: ", rErr) 1153} 1154``` 1155 1156<a name="RemoveObjectsWithContext"></a> 1157### RemoveObjectsWithContext(ctx context.Context, bucketName string, objectsCh chan string) (errorCh <-chan RemoveObjectError) 1158*Identical to RemoveObjects operation, but accepts a context for request cancellation.* 1159 1160Parameters 1161 1162|Param |Type |Description | 1163|:---|:---| :---| 1164|`ctx` | _context.Context_ |Request context | 1165|`bucketName` | _string_ |Name of the bucket | 1166|`objectsCh` | _chan string_ | Channel of objects to be removed | 1167 1168 1169__Return Values__ 1170 1171|Param |Type |Description | 1172|:---|:---| :---| 1173|`errorCh` | _<-chan minio.RemoveObjectError_ | Receive-only channel of errors observed during deletion. | 1174 1175```go 1176objectsCh := make(chan string) 1177ctx, cancel := context.WithTimeout(context.Background(), 100 * time.Second) 1178defer cancel() 1179 1180// Send object names that are needed to be removed to objectsCh 1181go func() { 1182 defer close(objectsCh) 1183 // List all objects from a bucket-name with a matching prefix. 1184 for object := range minioClient.ListObjects("my-bucketname", "my-prefixname", true, nil) { 1185 if object.Err != nil { 1186 log.Fatalln(object.Err) 1187 } 1188 objectsCh <- object.Key 1189 } 1190}() 1191 1192for rErr := range minioClient.RemoveObjects(ctx, "my-bucketname", objectsCh) { 1193 fmt.Println("Error detected during deletion: ", rErr) 1194} 1195``` 1196<a name="RemoveObjectWithOptions"></a> 1197### RemoveObjectWithOptions(bucketName, objectName string, opts minio.RemoveObjectOptions) error 1198Removes an object. 1199 1200__Parameters__ 1201 1202 1203|Param |Type |Description | 1204|:---|:---| :---| 1205|`bucketName` | _string_ |Name of the bucket | 1206|`objectName` | _string_ |Name of the object | 1207|`opts` |_minio.RemoveObjectOptions_ |Allows user to set options | 1208 1209__minio.RemoveObjectOptions__ 1210 1211|Field | Type | Description | 1212|:--- |:--- | :--- | 1213| `opts.GovernanceBypass` | _bool_ |Set the bypass governance header to delete an object locked with GOVERNANCE mode| 1214| `opts.VersionID` | _string_ |Version ID of the object to delete| 1215 1216 1217```go 1218opts := minio.RemoveObjectOptions { 1219 GovernanceBypass: true, 1220 VersionID: "myversionid", 1221 } 1222err = minioClient.RemoveObjectWithOptions("mybucket", "myobject", opts) 1223if err != nil { 1224 fmt.Println(err) 1225 return 1226} 1227``` 1228<a name="PutObjectRetention"></a> 1229### PutObjectRetention(bucketName, objectName string, opts minio.PutObjectRetentionOptions) error 1230Applies object retention lock onto an object. 1231 1232__Parameters__ 1233 1234 1235|Param |Type |Description | 1236|:---|:---| :---| 1237|`bucketName` | _string_ |Name of the bucket | 1238|`objectName` | _string_ |Name of the object | 1239|`opts` |_minio.PutObjectRetentionOptions_ |Allows user to set options like retention mode, expiry date and version id | 1240 1241__minio.PutObjectRetentionOptions__ 1242 1243|Field | Type | Description | 1244|:--- |:--- | :--- | 1245| `opts.GovernanceBypass` | _bool_ |Set the bypass governance header to overwrite object retention if the existing retention mode is set to GOVERNANCE| 1246| `opts.Mode` | _*minio.RetentionMode_ |Retention mode to be set| 1247| `opts.RetainUntilDate` | _*time.Time_ |Time until which the retention applied is valid| 1248| `opts.VersionID` | _string_ |Version ID of the object to apply retention on| 1249 1250```go 1251t := time.Date(2020, time.November, 18, 14, 0, 0, 0, time.UTC) 1252m := minio.RetentionMode(minio.Compliance) 1253opts := minio.PutObjectRetentionOptions { 1254 GovernanceBypass: true, 1255 RetainUntilDate: &t, 1256 Mode: &m, 1257 } 1258err = minioClient.PutObjectRetention("mybucket", "myobject", opts) 1259if err != nil { 1260 fmt.Println(err) 1261 return 1262} 1263``` 1264<a name="GetObjectRetention"></a> 1265### GetObjectRetention(bucketName, objectName, versionID string) (mode *RetentionMode, retainUntilDate *time.Time, err error) 1266Returns retention set on a given object. 1267 1268__Parameters__ 1269 1270 1271|Param |Type |Description | 1272|:---|:---| :---| 1273|`bucketName` | _string_ |Name of the bucket | 1274|`objectName` | _string_ |Name of the object | 1275|`versionID` |_string_ |Version ID of the object | 1276 1277```go 1278err = minioClient.PutObjectRetention("mybucket", "myobject", "") 1279if err != nil { 1280 fmt.Println(err) 1281 return 1282} 1283``` 1284<a name="PutObjectLegalHold"></a> 1285### PutObjectLegalHold(bucketName, objectName string, opts minio.PutObjectLegalHoldOptions) error 1286Applies legal-hold onto an object. 1287 1288__Parameters__ 1289 1290 1291|Param |Type |Description | 1292|:---|:---| :---| 1293|`bucketName` | _string_ |Name of the bucket | 1294|`objectName` | _string_ |Name of the object | 1295|`opts` |_minio.PutObjectLegalHoldOptions_ |Allows user to set options like status and version id | 1296 1297_minio.PutObjectLegalHoldOptions_ 1298 1299|Field | Type | Description | 1300|:--- |:--- | :--- | 1301| `opts.Status` | _*minio.LegalHoldStatus_ |Legal-Hold status to be set| 1302| `opts.VersionID` | _string_ |Version ID of the object to apply retention on| 1303 1304```go 1305s := minio.LegalHoldEnabled 1306opts := minio.PutObjectLegalHoldOptions { 1307 Status: &s, 1308} 1309err = minioClient.PutObjectLegalHold("mybucket", "myobject", opts) 1310if err != nil { 1311 fmt.Println(err) 1312 return 1313} 1314``` 1315<a name="GetObjectLegalHold"></a> 1316### GetObjectLegalHold(bucketName, objectName, versionID string) (status *LegalHoldStatus, err error) 1317Returns legal-hold status on a given object. 1318 1319__Parameters__ 1320 1321|Param |Type |Description | 1322|:---|:---| :---| 1323|`bucketName` | _string_ |Name of the bucket | 1324|`objectName` | _string_ |Name of the object | 1325|`opts` |_minio.GetObjectLegalHoldOptions_ |Allows user to set options like version id | 1326 1327```go 1328opts := minio.GetObjectLegalHoldOptions{} 1329err = minioClient.GetObjectLegalHold("mybucket", "myobject", opts) 1330if err != nil { 1331 fmt.Println(err) 1332 return 1333} 1334``` 1335<a name="SelectObjectContent"></a> 1336### SelectObjectContent(ctx context.Context, bucketName string, objectsName string, expression string, options SelectObjectOptions) *SelectResults 1337Parameters 1338 1339|Param |Type |Description | 1340|:---|:---| :---| 1341|`ctx` | _context.Context_ |Request context | 1342|`bucketName` | _string_ |Name of the bucket | 1343|`objectName` | _string_ |Name of the object | 1344|`options` | _SelectObjectOptions_ | Query Options | 1345 1346__Return Values__ 1347 1348|Param |Type |Description | 1349|:---|:---| :---| 1350|`SelectResults` | _SelectResults_ | Is an io.ReadCloser object which can be directly passed to csv.NewReader for processing output. | 1351 1352```go 1353 // Initialize minio client object. 1354 minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL) 1355 if err != nil { 1356 log.Fatalln(err) 1357 } 1358 1359 opts := minio.SelectObjectOptions{ 1360 Expression: "select count(*) from s3object", 1361 ExpressionType: minio.QueryExpressionTypeSQL, 1362 InputSerialization: minio.SelectObjectInputSerialization{ 1363 CompressionType: minio.SelectCompressionNONE, 1364 CSV: &minio.CSVInputOptions{ 1365 FileHeaderInfo: minio.CSVFileHeaderInfoNone, 1366 RecordDelimiter: "\n", 1367 FieldDelimiter: ",", 1368 }, 1369 }, 1370 OutputSerialization: minio.SelectObjectOutputSerialization{ 1371 CSV: &minio.CSVOutputOptions{ 1372 RecordDelimiter: "\n", 1373 FieldDelimiter: ",", 1374 }, 1375 }, 1376 } 1377 1378 reader, err := s3Client.SelectObjectContent(context.Background(), "mycsvbucket", "mycsv.csv", opts) 1379 if err != nil { 1380 log.Fatalln(err) 1381 } 1382 defer reader.Close() 1383 1384 if _, err := io.Copy(os.Stdout, reader); err != nil { 1385 log.Fatalln(err) 1386 } 1387``` 1388 1389<a name="PutObjectTagging"></a> 1390### PutObjectTagging(bucketName, objectName string, objectTags map[string]string) error 1391Adds or replace Object Tags to the given object 1392 1393__Parameters__ 1394 1395 1396|Param |Type |Description | 1397|:---|:---| :---| 1398|`bucketName` | _string_ |Name of the bucket | 1399|`objectName` | _string_ |Name of the object | 1400|`objectTags` | _map[string]string_ | Map with Object Tag's Key and Value | 1401 1402__Example__ 1403 1404 1405```go 1406err = minioClient.PutObjectTagging(bucketName, objectName, objectTags) 1407if err != nil { 1408 fmt.Println(err) 1409 return 1410} 1411``` 1412 1413<a name="PutObjectTaggingWithContext"></a> 1414### PutObjectTaggingWithContext(ctx context.Context, sssbucketName, objectName string, objectTags map[string]string) error 1415Identical to PutObjectTagging, but allows setting context to allow controlling context cancellations and timeouts. 1416 1417__Parameters__ 1418 1419 1420|Param |Type |Description | 1421|:---|:---| :---| 1422|`ctx` | _context.Context_ |Request context | 1423|`bucketName` | _string_ |Name of the bucket | 1424|`objectName` | _string_ |Name of the object | 1425|`objectTags` | _map[string]string_ | Map with Object Tag's Key and Value | 1426 1427__Example__ 1428 1429 1430```go 1431err = minioClient.PutObjectTaggingWithContext(ctx, bucketName, objectName, objectTags) 1432if err != nil { 1433 fmt.Println(err) 1434 return 1435} 1436``` 1437 1438<a name="GetObjectTagging"></a> 1439### GetObjectTagging(bucketName, objectName string) (string, error) 1440Fetch Object Tags from the given object 1441 1442__Parameters__ 1443 1444 1445|Param |Type |Description | 1446|:---|:---| :---| 1447|`bucketName` | _string_ |Name of the bucket | 1448|`objectName` | _string_ |Name of the object | 1449 1450__Example__ 1451 1452 1453```go 1454tags, err = minioClient.GetObjectTagging(bucketName, objectName) 1455if err != nil { 1456 fmt.Println(err) 1457 return 1458} 1459fmt.Printf("Fetched Tags: %s", tags) 1460``` 1461 1462<a name="GetObjectTaggingWithContext"></a> 1463### GetObjectTaggingWithContext(ctx context.Context, bucketName, objectName string) (string, error) 1464Identical to GetObjectTagging, but allows setting context to allow controlling context cancellations and timeouts. 1465 1466__Parameters__ 1467 1468 1469|Param |Type |Description | 1470|:---|:---| :---| 1471|`ctx` | _context.Context_ |Request context | 1472|`bucketName` | _string_ |Name of the bucket | 1473|`objectName` | _string_ |Name of the object | 1474 1475__Example__ 1476 1477 1478```go 1479tags, err = minioClient.GetObjectTaggingWithContext(ctx, bucketName, objectName) 1480if err != nil { 1481 fmt.Println(err) 1482 return 1483} 1484fmt.Printf("Fetched Tags: %s", tags) 1485``` 1486 1487<a name="RemoveObjectTagging"></a> 1488### RemoveObjectTagging(bucketName, objectName string) error 1489Remove Object Tags from the given object 1490 1491__Parameters__ 1492 1493 1494|Param |Type |Description | 1495|:---|:---| :---| 1496|`bucketName` | _string_ |Name of the bucket | 1497|`objectName` | _string_ |Name of the object | 1498 1499__Example__ 1500 1501 1502```go 1503err = minioClient.RemoveObjectTagging(bucketName, objectName) 1504if err != nil { 1505 fmt.Println(err) 1506 return 1507} 1508``` 1509 1510<a name="RemoveObjectTaggingWithContext"></a> 1511### RemoveObjectTaggingWithContext(ctx context.Context, bucketName, objectName string) error 1512Identical to RemoveObjectTagging, but allows setting context to allow controlling context cancellations and timeouts. 1513 1514__Parameters__ 1515 1516 1517|Param |Type |Description | 1518|:---|:---| :---| 1519|`ctx` | _context.Context_ |Request context | 1520|`bucketName` | _string_ |Name of the bucket | 1521|`objectName` | _string_ |Name of the object | 1522 1523__Example__ 1524 1525 1526```go 1527err = minioClient.RemoveObjectTaggingWithContext(ctx, bucketName, objectName) 1528if err != nil { 1529 fmt.Println(err) 1530 return 1531} 1532``` 1533 1534<a name="RemoveIncompleteUpload"></a> 1535### RemoveIncompleteUpload(bucketName, objectName string) error 1536Removes a partially uploaded object. 1537 1538__Parameters__ 1539 1540 1541|Param |Type |Description | 1542|:---|:---| :---| 1543|`bucketName` | _string_ |Name of the bucket | 1544|`objectName` | _string_ |Name of the object | 1545 1546__Example__ 1547 1548 1549```go 1550err = minioClient.RemoveIncompleteUpload("mybucket", "myobject") 1551if err != nil { 1552 fmt.Println(err) 1553 return 1554} 1555``` 1556 1557## 5. Presigned operations 1558 1559<a name="PresignedGetObject"></a> 1560### PresignedGetObject(bucketName, objectName string, expiry time.Duration, reqParams url.Values) (*url.URL, error) 1561Generates a presigned URL for HTTP GET operations. Browsers/Mobile clients may point to this URL to directly download objects even if the bucket is private. This presigned URL can have an associated expiration time in seconds after which it is no longer operational. The default expiry is set to 7 days. 1562 1563__Parameters__ 1564 1565 1566|Param |Type |Description | 1567|:---|:---| :---| 1568|`bucketName` | _string_ |Name of the bucket | 1569|`objectName` | _string_ |Name of the object | 1570|`expiry` | _time.Duration_ |Expiry of presigned URL in seconds | 1571|`reqParams` | _url.Values_ |Additional response header overrides supports _response-expires_, _response-content-type_, _response-cache-control_, _response-content-disposition_. | 1572 1573 1574__Example__ 1575 1576 1577```go 1578// Set request parameters for content-disposition. 1579reqParams := make(url.Values) 1580reqParams.Set("response-content-disposition", "attachment; filename=\"your-filename.txt\"") 1581 1582// Generates a presigned url which expires in a day. 1583presignedURL, err := minioClient.PresignedGetObject("mybucket", "myobject", time.Second * 24 * 60 * 60, reqParams) 1584if err != nil { 1585 fmt.Println(err) 1586 return 1587} 1588fmt.Println("Successfully generated presigned URL", presignedURL) 1589``` 1590 1591<a name="PresignedPutObject"></a> 1592### PresignedPutObject(bucketName, objectName string, expiry time.Duration) (*url.URL, error) 1593Generates a presigned URL for HTTP PUT operations. Browsers/Mobile clients may point to this URL to upload objects directly to a bucket even if it is private. This presigned URL can have an associated expiration time in seconds after which it is no longer operational. The default expiry is set to 7 days. 1594 1595NOTE: you can upload to S3 only with specified object name. 1596 1597__Parameters__ 1598 1599 1600|Param |Type |Description | 1601|:---|:---| :---| 1602|`bucketName` | _string_ |Name of the bucket | 1603|`objectName` | _string_ |Name of the object | 1604|`expiry` | _time.Duration_ |Expiry of presigned URL in seconds | 1605 1606 1607__Example__ 1608 1609 1610```go 1611// Generates a url which expires in a day. 1612expiry := time.Second * 24 * 60 * 60 // 1 day. 1613presignedURL, err := minioClient.PresignedPutObject("mybucket", "myobject", expiry) 1614if err != nil { 1615 fmt.Println(err) 1616 return 1617} 1618fmt.Println("Successfully generated presigned URL", presignedURL) 1619``` 1620 1621<a name="PresignedHeadObject"></a> 1622### PresignedHeadObject(bucketName, objectName string, expiry time.Duration, reqParams url.Values) (*url.URL, error) 1623Generates a presigned URL for HTTP HEAD operations. Browsers/Mobile clients may point to this URL to directly get metadata from objects even if the bucket is private. This presigned URL can have an associated expiration time in seconds after which it is no longer operational. The default expiry is set to 7 days. 1624 1625__Parameters__ 1626 1627|Param |Type |Description | 1628|:---|:---| :---| 1629|`bucketName` | _string_ |Name of the bucket | 1630|`objectName` | _string_ |Name of the object | 1631|`expiry` | _time.Duration_ |Expiry of presigned URL in seconds | 1632|`reqParams` | _url.Values_ |Additional response header overrides supports _response-expires_, _response-content-type_, _response-cache-control_, _response-content-disposition_. | 1633 1634 1635__Example__ 1636 1637 1638```go 1639// Set request parameters for content-disposition. 1640reqParams := make(url.Values) 1641reqParams.Set("response-content-disposition", "attachment; filename=\"your-filename.txt\"") 1642 1643// Generates a presigned url which expires in a day. 1644presignedURL, err := minioClient.PresignedHeadObject("mybucket", "myobject", time.Second * 24 * 60 * 60, reqParams) 1645if err != nil { 1646 fmt.Println(err) 1647 return 1648} 1649fmt.Println("Successfully generated presigned URL", presignedURL) 1650``` 1651 1652<a name="PresignedPostPolicy"></a> 1653### PresignedPostPolicy(PostPolicy) (*url.URL, map[string]string, error) 1654Allows setting policy conditions to a presigned URL for POST operations. Policies such as bucket name to receive object uploads, key name prefixes, expiry policy may be set. 1655 1656```go 1657// Initialize policy condition config. 1658policy := minio.NewPostPolicy() 1659 1660// Apply upload policy restrictions: 1661policy.SetBucket("mybucket") 1662policy.SetKey("myobject") 1663policy.SetExpires(time.Now().UTC().AddDate(0, 0, 10)) // expires in 10 days 1664 1665// Only allow 'png' images. 1666policy.SetContentType("image/png") 1667 1668// Only allow content size in range 1KB to 1MB. 1669policy.SetContentLengthRange(1024, 1024*1024) 1670 1671// Add a user metadata using the key "custom" and value "user" 1672policy.SetUserMetadata("custom", "user") 1673 1674// Get the POST form key/value object: 1675url, formData, err := minioClient.PresignedPostPolicy(policy) 1676if err != nil { 1677 fmt.Println(err) 1678 return 1679} 1680 1681// POST your content from the command line using `curl` 1682fmt.Printf("curl ") 1683for k, v := range formData { 1684 fmt.Printf("-F %s=%s ", k, v) 1685} 1686fmt.Printf("-F file=@/etc/bash.bashrc ") 1687fmt.Printf("%s\n", url) 1688``` 1689 1690## 6. Bucket policy/notification operations 1691 1692<a name="SetBucketPolicy"></a> 1693### SetBucketPolicy(bucketname, policy string) error 1694Set access permissions on bucket or an object prefix. 1695 1696__Parameters__ 1697 1698|Param |Type |Description | 1699|:---|:---| :---| 1700|`bucketName` | _string_ |Name of the bucket| 1701|`policy` | _string_ |Policy to be set | 1702 1703__Return Values__ 1704 1705|Param |Type |Description | 1706|:---|:---| :---| 1707|`err` | _error_ |Standard Error | 1708 1709__Example__ 1710 1711```go 1712policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Principal": {"AWS": ["*"]},"Resource": ["arn:aws:s3:::my-bucketname/*"],"Sid": ""}]}` 1713 1714err = minioClient.SetBucketPolicy("my-bucketname", policy) 1715if err != nil { 1716 fmt.Println(err) 1717 return 1718} 1719``` 1720 1721<a name="GetBucketPolicy"></a> 1722### GetBucketPolicy(bucketName) (policy string, error) 1723Get access permissions on a bucket or a prefix. 1724 1725__Parameters__ 1726 1727 1728|Param |Type |Description | 1729|:---|:---| :---| 1730|`bucketName` | _string_ |Name of the bucket | 1731 1732__Return Values__ 1733 1734 1735|Param |Type |Description | 1736|:---|:---| :---| 1737|`policy` | _string_ |Policy returned from the server | 1738|`err` | _error_ |Standard Error | 1739 1740__Example__ 1741 1742```go 1743policy, err := minioClient.GetBucketPolicy("my-bucketname") 1744if err != nil { 1745 log.Fatalln(err) 1746} 1747``` 1748 1749<a name="GetBucketNotification"></a> 1750### GetBucketNotification(bucketName string) (BucketNotification, error) 1751Get notification configuration on a bucket. 1752 1753__Parameters__ 1754 1755 1756|Param |Type |Description | 1757|:---|:---| :---| 1758|`bucketName` | _string_ |Name of the bucket | 1759 1760__Return Values__ 1761 1762 1763|Param |Type |Description | 1764|:---|:---| :---| 1765|`bucketNotification` | _minio.BucketNotification_ |structure which holds all notification configurations| 1766|`err` | _error_ |Standard Error | 1767 1768__Example__ 1769 1770 1771```go 1772bucketNotification, err := minioClient.GetBucketNotification("mybucket") 1773if err != nil { 1774 fmt.Println("Failed to get bucket notification configurations for mybucket", err) 1775 return 1776} 1777 1778for _, queueConfig := range bucketNotification.QueueConfigs { 1779 for _, e := range queueConfig.Events { 1780 fmt.Println(e + " event is enabled") 1781 } 1782} 1783``` 1784 1785<a name="SetBucketNotification"></a> 1786### SetBucketNotification(bucketName string, bucketNotification BucketNotification) error 1787Set a new bucket notification on a bucket. 1788 1789__Parameters__ 1790 1791 1792|Param |Type |Description | 1793|:---|:---| :---| 1794|`bucketName` | _string_ |Name of the bucket | 1795|`bucketNotification` | _minio.BucketNotification_ |Represents the XML to be sent to the configured web service | 1796 1797__Return Values__ 1798 1799 1800|Param |Type |Description | 1801|:---|:---| :---| 1802|`err` | _error_ |Standard Error | 1803 1804__Example__ 1805 1806 1807```go 1808queueArn := minio.NewArn("aws", "sqs", "us-east-1", "804605494417", "PhotoUpdate") 1809 1810queueConfig := minio.NewNotificationConfig(queueArn) 1811queueConfig.AddEvents(minio.ObjectCreatedAll, minio.ObjectRemovedAll) 1812queueConfig.AddFilterPrefix("photos/") 1813queueConfig.AddFilterSuffix(".jpg") 1814 1815bucketNotification := minio.BucketNotification{} 1816bucketNotification.AddQueue(queueConfig) 1817 1818err = minioClient.SetBucketNotification("mybucket", bucketNotification) 1819if err != nil { 1820 fmt.Println("Unable to set the bucket notification: ", err) 1821 return 1822} 1823``` 1824 1825<a name="RemoveAllBucketNotification"></a> 1826### RemoveAllBucketNotification(bucketName string) error 1827Remove all configured bucket notifications on a bucket. 1828 1829__Parameters__ 1830 1831 1832|Param |Type |Description | 1833|:---|:---| :---| 1834|`bucketName` | _string_ |Name of the bucket | 1835 1836__Return Values__ 1837 1838 1839|Param |Type |Description | 1840|:---|:---| :---| 1841|`err` | _error_ |Standard Error | 1842 1843__Example__ 1844 1845 1846```go 1847err = minioClient.RemoveAllBucketNotification("mybucket") 1848if err != nil { 1849 fmt.Println("Unable to remove bucket notifications.", err) 1850 return 1851} 1852``` 1853 1854<a name="ListenBucketNotification"></a> 1855### ListenBucketNotification(bucketName, prefix, suffix string, events []string, doneCh <-chan struct{}) <-chan NotificationInfo 1856ListenBucketNotification API receives bucket notification events through the notification channel. The returned notification channel has two fields 'Records' and 'Err'. 1857 1858- 'Records' holds the notifications received from the server. 1859- 'Err' indicates any error while processing the received notifications. 1860 1861NOTE: Notification channel is closed at the first occurrence of an error. 1862 1863__Parameters__ 1864 1865 1866|Param |Type |Description | 1867|:---|:---| :---| 1868|`bucketName` | _string_ | Bucket to listen notifications on | 1869|`prefix` | _string_ | Object key prefix to filter notifications for | 1870|`suffix` | _string_ | Object key suffix to filter notifications for | 1871|`events` | _[]string_ | Enables notifications for specific event types | 1872|`doneCh` | _chan struct{}_ | A message on this channel ends the ListenBucketNotification iterator | 1873 1874__Return Values__ 1875 1876|Param |Type |Description | 1877|:---|:---| :---| 1878|`notificationInfo` | _chan minio.NotificationInfo_ | Channel of bucket notifications | 1879 1880__minio.NotificationInfo__ 1881 1882|Field |Type |Description | 1883|`notificationInfo.Records` | _[]minio.NotificationEvent_ | Collection of notification events | 1884|`notificationInfo.Err` | _error_ | Carries any error occurred during the operation (Standard Error) | 1885 1886 1887__Example__ 1888 1889 1890```go 1891// Create a done channel to control 'ListenBucketNotification' go routine. 1892doneCh := make(chan struct{}) 1893 1894// Indicate a background go-routine to exit cleanly upon return. 1895defer close(doneCh) 1896 1897// Listen for bucket notifications on "mybucket" filtered by prefix, suffix and events. 1898for notificationInfo := range minioClient.ListenBucketNotification("mybucket", "myprefix/", ".mysuffix", []string{ 1899 "s3:ObjectCreated:*", 1900 "s3:ObjectAccessed:*", 1901 "s3:ObjectRemoved:*", 1902 }, doneCh) { 1903 if notificationInfo.Err != nil { 1904 fmt.Println(notificationInfo.Err) 1905 } 1906 fmt.Println(notificationInfo) 1907} 1908``` 1909 1910<a name="SetBucketLifecycle"></a> 1911### SetBucketLifecycle(bucketname, lifecycle string) error 1912Set lifecycle on bucket or an object prefix. 1913 1914__Parameters__ 1915 1916|Param |Type |Description | 1917|:---|:---| :---| 1918|`bucketName` | _string_ |Name of the bucket| 1919|`lifecycle` | _string_ |Lifecycle to be set | 1920 1921__Return Values__ 1922 1923|Param |Type |Description | 1924|:---|:---| :---| 1925|`err` | _error_ |Standard Error | 1926 1927__Example__ 1928 1929```go 1930lifecycle := `<LifecycleConfiguration> 1931 <Rule> 1932 <ID>expire-bucket</ID> 1933 <Prefix></Prefix> 1934 <Status>Enabled</Status> 1935 <Expiration> 1936 <Days>365</Days> 1937 </Expiration> 1938 </Rule> 1939</LifecycleConfiguration>` 1940 1941err = minioClient.SetBucketLifecycle("my-bucketname", lifecycle) 1942if err != nil { 1943 fmt.Println(err) 1944 return 1945} 1946``` 1947 1948<a name="GetBucketLifecycle"></a> 1949### GetBucketLifecycle(bucketName) (lifecycle string, error) 1950Get lifecycle on a bucket or a prefix. 1951 1952__Parameters__ 1953 1954 1955|Param |Type |Description | 1956|:---|:---| :---| 1957|`bucketName` | _string_ |Name of the bucket | 1958 1959__Return Values__ 1960 1961 1962|Param |Type |Description | 1963|:---|:---| :---| 1964|`lifecycle` | _string_ |Lifecycle returned from the server | 1965|`err` | _error_ |Standard Error | 1966 1967__Example__ 1968 1969```go 1970lifecycle, err := minioClient.GetBucketLifecycle("my-bucketname") 1971if err != nil { 1972 log.Fatalln(err) 1973} 1974``` 1975 1976<a name="SetBucketEncryption"></a> 1977### SetBucketEncryption(bucketname string, configuration ServerSideEncryptionConfiguration) error 1978Set default encryption configuration on a bucket. 1979 1980__Parameters__ 1981 1982|Param |Type |Description | 1983|:---|:---| :---| 1984|`bucketName` | _string_ |Name of the bucket| 1985|`configuration` | _minio.ServerSideEncyrptionConfiguration_ | Structure that holds default encryption configuration to be set | 1986 1987__Return Values__ 1988 1989|Param |Type |Description | 1990|:---|:---| :---| 1991|`err` | _error_ |Standard Error | 1992 1993__Example__ 1994 1995```go 1996s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) 1997if err != nil { 1998 log.Fatalln(err) 1999} 2000 2001// Initialize default encryption configuration structure 2002config := minio.ServerSideEncryptionConfiguration{Rules: []minio.Rule{ 2003 minio.Rule{ 2004 Apply: minio.ApplyServerSideEncryptionByDefault{ 2005 SSEAlgorithm: "AES256", 2006 }, 2007 }, 2008}} 2009// Set default encryption configuration on an S3 bucket 2010err = s3Client.SetBucketEncryption("my-bucketname", config) 2011if err != nil { 2012 log.Fatalln(err) 2013} 2014``` 2015 2016<a name="GetBucketEncryption"></a> 2017### GetBucketEncryption(bucketName string) (ServerSideEncryptionConfiguration, error) 2018Get default encryption configuration set on a bucket. 2019 2020__Parameters__ 2021 2022 2023|Param |Type |Description | 2024|:---|:---| :---| 2025|`bucketName` | _string_ |Name of the bucket | 2026 2027__Return Values__ 2028 2029 2030|Param |Type |Description | 2031|:---|:---| :---| 2032|`configuration` | _minio.ServerSideEncyrptionConfiguration_ | Structure that holds default encryption configuration | 2033|`err` | _error_ |Standard Error | 2034 2035__Example__ 2036 2037```go 2038s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) 2039if err != nil { 2040 log.Fatalln(err) 2041} 2042 2043// Get default encryption configuration set on an S3 bucket and print it out 2044encryptionConfig, err := s3Client.GetBucketEncryption("my-bucketname") 2045if err != nil { 2046 log.Fatalln(err) 2047} 2048fmt.Printf("%+v\n", encryptionConfig) 2049``` 2050 2051<a name="DeleteBucketEncryption"></a> 2052### DeleteBucketEncryption(bucketName string) (error) 2053Delete/Remove default encryption configuration set on a bucket. 2054 2055__Parameters__ 2056 2057 2058|Param |Type |Description | 2059|:---|:---|:---| 2060|`bucketName` | _string_ |Name of the bucket | 2061 2062__Return Values__ 2063 2064 2065|Param |Type |Description | 2066|:---|:---| :---| 2067|`err` | _error_ |Standard Error | 2068 2069__Example__ 2070 2071```go 2072err := s3Client.DeleteBucketEncryption("my-bucketname") 2073if err != nil { 2074 log.Fatalln(err) 2075} 2076// "my-bucket" is successfully deleted/removed. 2077``` 2078 2079<a name="SetBucketObjectLockConfig"></a> 2080### SetBucketObjectLockConfig(bucketname, mode *RetentionMode, validity *uint, unit *ValidityUnit) error 2081Set object lock configuration in given bucket. mode, validity and unit are either all set or all nil. 2082 2083__Parameters__ 2084 2085|Param |Type |Description | 2086|:---|:---| :---| 2087|`bucketName` | _string_ |Name of the bucket| 2088|`mode` | _RetentionMode_ |Retention mode to be set | 2089|`validity` | _uint_ |Validity period to be set | 2090|`unit` | _ValidityUnit_ |Unit of validity period | 2091 2092__Return Values__ 2093 2094|Param |Type |Description | 2095|:---|:---| :---| 2096|`err` | _error_ |Standard Error | 2097 2098__Example__ 2099 2100```go 2101mode := Governance 2102validity := uint(30) 2103unit := Days 2104 2105err = minioClient.SetBucketObjectLockConfig("my-bucketname", &mode, &validity, &unit) 2106if err != nil { 2107 fmt.Println(err) 2108 return 2109} 2110``` 2111 2112<a name="GetBucketObjectLockConfig"></a> 2113### GetBucketObjectLockConfig(bucketName) (*RetentionMode, *uint, *ValidityUnit, error) 2114Get object lock configuration of given bucket. 2115 2116__Parameters__ 2117 2118 2119|Param |Type |Description | 2120|:---|:---| :---| 2121|`bucketName` | _string_ |Name of the bucket | 2122 2123__Return Values__ 2124 2125 2126|Param |Type |Description | 2127|:---|:---| :---| 2128|`mode` | _RetentionMode_ |Current retention mode | 2129|`validity` | _uint_ |Current validity period | 2130|`unit` | _ValidityUnit_ |Unit of validity period | 2131|`err` | _error_ |Standard Error | 2132 2133__Example__ 2134 2135```go 2136mode, validity, unit, err := minioClient.GetObjectLockConfig("my-bucketname") 2137if err != nil { 2138 log.Fatalln(err) 2139} 2140 2141if mode != nil { 2142 fmt.Printf("%v mode is enabled for %v %v for bucket 'my-bucketname'\n", *mode, *validity, *unit) 2143} else { 2144 fmt.Println("No mode is enabled for bucket 'my-bucketname'") 2145} 2146``` 2147 2148<a name="EnableVersioning"></a> 2149### EnableVersioning(bucketName) error 2150Enable bucket versioning support. 2151 2152__Parameters__ 2153 2154 2155|Param |Type |Description | 2156|:---|:---| :---| 2157|`bucketName` | _string_ |Name of the bucket | 2158 2159__Return Values__ 2160 2161 2162|Param |Type |Description | 2163|:---|:---| :---| 2164|`err` | _error_ |Standard Error | 2165 2166__Example__ 2167 2168```go 2169err := minioClient.EnableVersioning("my-bucketname") 2170if err != nil { 2171 log.Fatalln(err) 2172} 2173 2174fmt.Println("versioning enabled for bucket 'my-bucketname'") 2175``` 2176 2177<a name="DisableVersioning"></a> 2178### DisableVersioning(bucketName) error 2179Disable bucket versioning support. 2180 2181__Parameters__ 2182 2183 2184|Param |Type |Description | 2185|:---|:---| :---| 2186|`bucketName` | _string_ |Name of the bucket | 2187 2188__Return Values__ 2189 2190 2191|Param |Type |Description | 2192|:---|:---| :---| 2193|`err` | _error_ |Standard Error | 2194 2195__Example__ 2196 2197```go 2198err := minioClient.DisableVersioning("my-bucketname") 2199if err != nil { 2200 log.Fatalln(err) 2201} 2202 2203fmt.Println("versioning disabled for bucket 'my-bucketname'") 2204``` 2205 2206## 7. Client custom settings 2207 2208<a name="SetAppInfo"></a> 2209### SetAppInfo(appName, appVersion string) 2210Add custom application details to User-Agent. 2211 2212__Parameters__ 2213 2214| Param | Type | Description | 2215|---|---|---| 2216|`appName` | _string_ | Name of the application performing the API requests. | 2217| `appVersion`| _string_ | Version of the application performing the API requests. | 2218 2219 2220__Example__ 2221 2222 2223```go 2224// Set Application name and version to be used in subsequent API requests. 2225minioClient.SetAppInfo("myCloudApp", "1.0.0") 2226``` 2227 2228<a name="SetCustomTransport"></a> 2229### SetCustomTransport(customHTTPTransport http.RoundTripper) 2230Overrides default HTTP transport. This is usually needed for debugging or for adding custom TLS certificates. 2231 2232__Parameters__ 2233 2234| Param | Type | Description | 2235|---|---|---| 2236|`customHTTPTransport` | _http.RoundTripper_ | Custom transport e.g, to trace API requests and responses for debugging purposes.| 2237 2238 2239<a name="TraceOn"></a> 2240### TraceOn(outputStream io.Writer) 2241Enables HTTP tracing. The trace is written to the io.Writer provided. If outputStream is nil, trace is written to os.Stdout. 2242 2243__Parameters__ 2244 2245| Param | Type | Description | 2246|---|---|---| 2247|`outputStream` | _io.Writer_ | HTTP trace is written into outputStream.| 2248 2249 2250<a name="TraceOff"></a> 2251### TraceOff() 2252Disables HTTP tracing. 2253 2254<a name="SetS3TransferAccelerate"></a> 2255### SetS3TransferAccelerate(acceleratedEndpoint string) 2256Set AWS S3 transfer acceleration endpoint for all API requests hereafter. 2257NOTE: This API applies only to AWS S3 and is a no operation for S3 compatible object storage services. 2258 2259__Parameters__ 2260 2261| Param | Type | Description | 2262|---|---|---| 2263|`acceleratedEndpoint` | _string_ | Set to new S3 transfer acceleration endpoint.| 2264