You can use resumable upload to split an object into multiple parts and upload them simultaneously. After all parts have been uploaded, you can combine the uploaded parts into a complete object to finish the upload.

During the upload, the upload progress is recorded in a checkpoint file. If the upload of a part fails, the next upload starts from the position recorded in the checkpoint file. The checkpoint file is deleted after resumable upload is complete.

Note
  • The SDK records the upload progress in the checkpoint file. Make sure that you have write permissions on the checkpoint file. The checkpoint file contains a checksum. This file cannot be edited. If the checkpoint file is damaged, you must upload all parts again.
  • If the object being uploaded is modified, you must upload the entire object again.

You can use Bucket.UploadFile to upload an object by using resumable upload. The following table describes the parameters of this operation.

Parameter Description
objectKey The name of the object to be uploaded to OSS.
filePath The local file path from which to upload the object.
partSize The size of each part. The part size ranges from 100 KB to 5 GB.
options The optional parameters, including:
  • Routines: the number of concurrent upload threads. The default value is 1, indicating that only one thread is used to upload the parts.
  • Checkpoint: specifies whether resumable upload is enabled and the path of the checkpoint file. By default, resumable upload is disabled. For example, oss.Checkpoint(true, "") indicates that resumable upload is enabled and the checkpoint file is the file.cp file contained in the same directory as the source local file. file is a variable that indicates the local file name. You can also use oss.Checkpoint(true, "your-cp-file.cp") to specify the checkpoint file.
  • For more information about other metadata, see Manage object metadata.
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)
    }

    // Specify the name of the bucket to which to upload the object.
    bucket, err := client.Bucket("<yourBucketName>")
    if err ! = nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }

    // The part size is 100 KB. Start resumable upload. Upload the parts by using three concurrent threads.
    // yourObjectName is equivalent to the objectKey and indicates the complete path of the object that you want to upload to OSS. The path must include the file extension of the object. For example, you can set yourObjectName to abc/efg/123.jpg.
    // LocalFile is the filePath value. 100*1024 is the partSize value.
    err = bucket.UploadFile("<yourObjectName>", "LocalFile", 100*1024, oss.Routines(3), oss.Checkpoint(true, ""))
    if err ! = nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }
}