All Products
Search
Document Center

Object Storage Service:Upload objects using the cp command

Last Updated:May 28, 2025

You can run the cp command to upload local resources, such as files, images, and videos, to Object Storage Service (OSS). For example, you can run the cp command to upload a large file.

Usage notes

  • To upload a local file, you must have the oss:PutObject, oss:ListParts, and oss:AbortMultipartUpload permissions. For more information, see Attach a custom policy to a RAM user.

  • You can perform batch upload only if you set the source parameter to a directory.

Command syntax

ossutil cp source dest [flags]

Parameter

Type

Description

source

string

The path of the local file that you want to upload. The path can be a relative path, absolute path, or -. If you set the source parameter to -, the path is read from the standard input.

dest

string

The path in which you want to store the uploaded local file. Example: oss://bucket[/prefix].

--acl

string

The access control list (ACL) of the object. Valid values:

  • private: private

  • public-read: public-read.

  • public-read-write: public-read-write

  • default: inherited from the bucket

--bigfile-threshold

int

The object size threshold for multipart upload, download, and copy. Default value: 104857600.

--cache-control

string

The caching behavior of the web page when the object is downloaded.

--content-disposition

string

The display form of the object.

--content-encoding

string

The encoding method used to encode the object.

--content-type

string

The content type of the object.

--copy-props

string

The attributes of the local file that you want to upload. Valid values:

  • none

  • metadata

  • default

-d, --dirs

string

Specifies that the objects and subdirectories in the current directory are returned.

--encoding-type

string

The encoding method used to encode the object or file name. Valid value: url.

--end-with

string

Specifies that objects whose names are alphabetically before or the same as the value of the --end-with parameter are returned.

--exclude

stringArray

The exclusion rule for the path or local file name.

--exclude-from

stringArray

Specifies that the exclusion rule is read from the rules file.

--expires

stringArray

The absolute expiration time of the cached content.

--files-from

stringArray

Specifies that the local file names are read from the rules file, and empty lines or comment lines are ignored.

--files-from-raw

stringArray

Specifies that the local file names are read from the rules file.

--filter

stringArray

The filter rule for the path or local file name.

--filter-from

stringArray

Specifies that the filter rule for the path or local file name is read from the rules file.

-f, --force

/

Specifies that the command is forcibly run without a prompt for confirmation.

--include

stringArray

The inclusion rule for the path or local file name.

Note

For more information, see Filter options.

--include-from

stringArray

Specifies that the inclusion rule is read from the rules file.

-j, --job

int

The number of concurrent tasks that can be performed across multiple objects. Default value: 3.

--listObjects

/

Specifies that the ListObjects operation is called to list objects.

--max-size

SizeSuffix

The maximum size of the local file that can be uploaded. The default unit is bytes. The unit of local file size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1,024 bytes.

--metadata

strings

The user metadata of the object in the key=value format.

--metadata-directive

string

The method used to configure the metadata of the object. Valid values:

  • COPY

  • REPLACE

--metadata-exclude

stringArray

The exclusion rule for object metadata.

--metadata-filter

stringArray

The filtering rule for object metadata.

--metadata-filter-from

stringArray

Specifies that the filtering rule for object metadata is read from the rules file.

--metadata-include

stringArray

The inclusion rule for object metadata.

--min-age

Duration

Specifies that objects last modified after the start of the specified time range are excluded. The default unit is s (seconds). You can suffix the numerical value with a unit of time. For example, 1h indicates one hour.

Note

--min-age 1h specifies that only objects modified an hour ago or earlier are uploaded.

--max-age

Duration

Specifies that only objects whose last modified time is within the specified time range are uploaded. The default unit is s (seconds). You can suffix the numerical value with a unit of time. For example, 1h indicates one hour.

Note

--max-age 1h specifies that only objects modified within the past hour are uploaded.

--min-mtime

Time

Specifies that only objects whose last modified time is later than the value of this option are uploaded. The time must be in UTC. Example: 2006-01-02T15:04:05.

Note

--min-mtime "2006-01-02T15:04:05" specifies that only objects modified after 15:04:05 on January 02,2006 are uploaded.

--max-mtime

Time

Specifies that only objects whose last modified time is earlier than the value of this option are uploaded. The time must be in UTC. Example: 2006-01-02T15:04:05.

--min-size

SizeSuffix

The minimum size of the local file that can be uploaded. The default unit is bytes. The unit of file size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1,024 bytes.

--no-progress

/

Specifies that the progress bar is not displayed.

--page-size

int

The maximum number of objects that can be returned. Default value: 1000. Valid values: 1 to 1000.

--parallel

int

The number of concurrent tasks for internal operations on a single object.

--part-size

SizeSuffix

The part size. By default, ossutil calculates the appropriate part size based on the local file size. Valid values: 100 KiB to 5 GiB.

-r, --recursive

/

Specifies that the command is recursively run on objects. If this parameter is specified, the cp command takes effect on all objects that meet the conditions in the bucket. Otherwise, the cp command takes effect only on the objects in the specified path.

--request-payer

string

The payer of the request. If pay-by-requester is enabled for the bucket, set this parameter to requester.

--size-only

/

Specifies that only when the size of the local file is different from that of the object, the local file is uploaded.

--storage-class

string

The storage class of the object. Valid values:

  • Standard

  • IA

  • Archive

  • ColdArchive

  • DeepColdArchive

--tagging

strings

The tags of the object in the key=value format.

--tagging-directive

string

The method used to configure the tags for the object. Valid values:

  • COPY

  • REPLACE

-u, --update

/

Specifies that only when the last modified time of the local file is later than that of the object, the local file is uploaded.

--ignore-existing

/

Skip objects that already exist.

Note

For more information, see Command-line options.

The naming rules for the object:

  • If a local file is uploaded and the prefix parameter is not specified, the name of the object is the name of the local file.

  • If a local file is uploaded and the value of the prefix parameter ends with a forward slash (/), the name of the object is in the following format: the value of the prefix parameter + the name of the local file.

  • If multiple local files are uploaded and the prefix parameter is not specified, the names of the objects are the relative paths of the local files.

  • If multiple local files are uploaded and the value of the prefix parameter ends with a forward slash (/), the names of the objects are in the following format: the value of the prefix parameter + the relative paths of the local files.

  • If multiple local files are uploaded and the value of the prefix parameter does not end with a forward slash (/), the names of the objects are in the following format: the value of the prefix parameter + / + the relative paths of the local files.

Note

The relative path of a local file is the part that follows the specified path in the cp command. For example, if the path specified in the cp command is /root/dir/, the relative path of the /root/dir/subdir/test.txt file is subdir/test.txt.

Examples

  • Upload a single file

    Upload the examplefile.txt file to the desfolder directory in the examplebucket bucket.

    ossutil cp D:/localpath/examplefile.txt oss://examplebucket/desfolder/
  • Upload only files in a specific directory

    Upload files in the localfolder directory to the desfolder directory in the examplebucket bucket.

    ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/
  • Batch upload files that meet specific conditions

    Upload all TXT files in the localfolder directory to the desfolder directory in the examplebucket bucket.

    ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ --include "*.txt"