This topic describes how to download an object from OSS to a local file.

Run the following code to download a specified object from OSSClient to your local file:

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Create an OSSClient instance.
	client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Obtain the bucket.
	bucket, err := client.Bucket("<yourBucketName>")
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Download an object to your local file.
	err = bucket.GetObjectToFile("<yourObjectName>", "LocalFile")
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
}