In a bucket with versioning enabled or suspended, the HeadObject operation only obtains the metadata of the current version of an object.
Note If the current version of the target object is a delete marker, the 404 Not Found
error is returned. You can specify the versionId to obtain the metadata of a specified
version of the target object.
You can run the following code to obtain the metadata of an object:
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Creates an OSSClient instance.
client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
objectName := "<yourObjectName>"
// Obtains the bucket.
bucket, err := client.Bucket("<yourBucketName>")
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Obtains a part of the metadata of the specified version of the object.
props, err := bucket.GetObjectMeta(objectName, oss.VersionId("youObjectVersionId"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Println("Object Meta:", props)
// Obtains all metadata of the specified version of the object.
props, err := bucket.GetObjectDetailedMeta(objectName, oss.VersionId("youObjectVersionId"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Println("Object Meta:", ret)
}
For more information about obtaining object metadata, see HeadObject and GetObjectMeta.