All Products
Search
Document Center

Object Storage Service:Resumable upload (OSS SDK for Go 1.0)

Last Updated:Jun 03, 2026

Use resumable upload to upload objects larger than 5 GB when network instability or program exceptions may interrupt the process. The object is split into parts and uploaded in parallel, with progress tracked in a checkpoint file. If a part fails, the upload resumes from the checkpoint. After all parts upload, they combine into a complete object.

Usage notes

  • In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access OSS from other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about OSS regions and endpoints, see Regions and Endpoints.

  • In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.

  • This topic demonstrates creating an OSSClient instance with an OSS endpoint. For alternative configurations, such as using a custom domain or authenticating with credentials from Security Token Service (STS), see Configure a client (Go SDK V1).

  • To use resumable upload, you must have the oss:PutObject permission. For more information, see Grant a custom policy.

  • Upload progress is recorded in the checkpoint file. Ensure you have write permissions on it.

  • The checkpoint file contains a checksum that must not be modified. If the file is damaged, re-upload all parts.

  • If the local file changes during upload, re-upload all parts.

Implementation

Call Bucket.UploadFile to perform resumable upload with the following parameters.

Parameter

Description

objectKey

The object name. Equivalent to objectName.

filePath

The path of the local file to upload.

partSize

The size of each part. Valid values: 100 KB to 5 GB. Default value: 100 KB.

options

Upload options:

  • Routines: the number of concurrent part uploads. Default: 1 (no concurrency).

  • Checkpoint: enables resumable upload and configures the checkpoint file. Disabled by default.

    oss.Checkpoint(true, "") enables resumable upload with the default checkpoint file (file.cp in the same directory as the local file, where file is the local filename). Use oss.Checkpoint(true, "your-cp-file.cp") to specify a custom checkpoint file.

Note

You can also set object metadata by using options. Manage object metadata.

Examples

The following sample code provides an example on how to perform resumable upload:

package main

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

func main() {
    // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
    provider, err := oss.NewEnvironmentVariableCredentialsProvider()
    if err != nil {
        log.Fatalf("Failed to create credentials provider: %v", err)
    }

    // Create an OSSClient instance. 
    // Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify your actual endpoint. 
    // Specify the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou. Specify your actual endpoint.
    clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
    clientOptions = append(clientOptions, oss.Region("yourRegion"))
    // Specify the signature version.
    clientOptions = append(clientOptions, oss.AuthVersion(oss.AuthV4))
    client, err := oss.New("yourEndpoint", "", "", clientOptions...)
    if err != nil {
        log.Fatalf("Failed to create OSS client: %v", err)
    }

    // Specify the name of the bucket. Example: examplebucket. 
    bucket, err := client.Bucket("examplebucket")
    if err != nil {
        log.Fatalf("Failed to get bucket: %v", err)
    }

     // When you use UploadFile to perform resumable upload, the number of parts cannot exceed 10000. 
    // Specify the size of each part based on the size of the object that you want to upload. The size of each part ranges from 100 KB to 5 GB. Default value: 100 KB (100 x 1024). 
    // Use oss.Routines to set the number of parts that can be uploaded in parallel to 3. 
    // Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt. 
    // Specify the full path of the local file. Example: D:\\localpath\\examplefile.txt. By default, if you do not specify the path of the local file, the file is uploaded from the path of the project to which the sample program belongs. 
    err = bucket.UploadFile("exampledir/exampleobject.txt", "D:\\localpath\\examplefile.txt", 100*1024, oss.Routines(3), oss.Checkpoint(true, ""))
    if err != nil {
        log.Fatalf("Failed to upload file: %v", err)
    }

    log.Println("File uploaded successfully.")
} 

FAQ

What do I do if "Too many parts, Please increase part size." is reported when I perform resumable upload?

References

  • Complete resumable upload sample code is available on GitHub.

  • API reference for the resumable upload method: UploadFile.