To upload local files, images, videos, or other resources to OSS—or to upload large files—use the cp command in ossutil.
Important notes
-
To upload files, you must have the
oss:PutObject,oss:ListParts, andoss:AbortMultipartUploadpermissions. For details, see Grant custom permission policies to RAM users. -
Batch upload is supported only when the source is a directory.
-
When you use the
-u, --updateoption, the system sends at least one HEAD request for each file to compare it with the destination object, regardless of whether the destination object exists. In scenarios where data changes infrequently, this generates many inefficient requests, which may degrade performance and incur extra request charges. Evaluate your business needs carefully before using this option to avoid unnecessary resource consumption.
Command syntax
ossutil cp source dest [flags]
|
Parameter |
Type |
Description |
|
source |
string |
Local file path. Supports relative paths, absolute paths, and |
|
dest |
string |
File path in the destination bucket. Example: |
|
--acl |
string |
Access permissions for the object. Valid values:
|
|
--bandwidth-limit |
SizeSuffix |
Limits network bandwidth to control data transfer rate. Minimum value is 1024 B/s. The default unit is B/s. When setting this parameter, specify a unit as needed. Valid units include B (bytes), K (kilobytes), M (megabytes), and G (gigabytes). For example, 50 M sets the bandwidth limit to 50 MB/s. |
|
--bigfile-threshold |
SizeSuffix |
Threshold (in bytes) to enable multipart upload, download, or copy for large files. Default value: 104857600. |
|
--cache-control |
string |
Specifies caching behavior when the object is downloaded by a web browser. |
|
--content-disposition |
string |
Specifies how the object is displayed. |
|
--content-encoding |
string |
Declares the encoding method of the object. |
|
--content-type |
string |
Content type of the object. |
|
--copy-props |
string |
Determines which properties to copy from the source object. Valid values:
|
|
--checkpoint-dir |
string |
|
|
-d, --dirs |
string |
List files and subdirectories in the current directory without recursively listing all files in subdirectories. |
|
--encoding-type |
string |
Encoding method for input object names or file names. Valid value: url. |
|
--end-with |
string |
Returns objects that come before or match the specified value in alphabetical order. |
|
--exclude |
stringArray |
Exclusion rules for paths or file names. |
|
--exclude-from |
stringArray |
Read exclusion rules from a rule file. |
|
--expires |
stringArray |
Specifies the absolute expiration time for cached content. |
|
--files-from |
stringArray |
Read a list of source file names from a file, ignoring empty lines and comment lines. Applies only to filtering scenarios. |
|
--files-from-raw |
stringArray |
Read a list of source file names from a file. Applies only to filtering scenarios. |
|
--filter |
stringArray |
Filtering rules for paths or file names. |
|
--filter-from |
stringArray |
Read filtering rules from a rule file. |
|
-f, --force |
/ |
Force the operation without prompting for confirmation. |
|
--include |
stringArray |
Inclusion rules for paths or file names. Note
For more information about filtering options, see Filtering options. |
|
--include-from |
stringArray |
Read inclusion rules from a rule file. |
|
-j, --job |
int |
Number of concurrent tasks. Default value: 3. Note
This option takes effect only when you also specify any of the following parameters: |
|
--listObjects |
/ |
Use the ListObjects API to list objects. |
|
--max-size |
SizeSuffix |
Maximum file size to transfer. Default unit is bytes. You can also use suffixes: B|K|M|G|T|P. Note: 1K (KiB) = 1024B. |
|
--metadata |
strings |
User-defined metadata for the object, in key=value format. |
|
--metadata-directive |
string |
Specifies how to set metadata for the destination object. Valid values:
|
|
--metadata-exclude |
stringArray |
Exclusion rules for object metadata. |
|
--metadata-filter |
stringArray |
Filtering rules for object metadata. |
|
--metadata-filter-from |
stringArray |
Read object metadata filtering rules from a rule file. |
|
--metadata-include |
stringArray |
Inclusion rules for object metadata. |
|
--min-age |
Duration |
Upload only files modified before the specified time interval. Default unit is seconds. You can use suffixes such as h (hours). Example: 1h means 1 hour. Note
|
|
--max-age |
Duration |
Upload only files modified within the specified time interval. Default unit is seconds. You can use suffixes such as h (hours). Example: 1h means 1 hour. Note
|
|
--min-mtime |
Time |
Upload only files modified after the specified time. Time format: UTC, for example, 2006-01-02T15:04:05. Note
|
|
--max-mtime |
Time |
Upload only files modified before the specified time. Time format: UTC, for example, 2006-01-02T15:04:05. |
|
--min-size |
SizeSuffix |
Minimum file size to transfer. Default unit is bytes. You can also use suffixes: B|K|M|G|T|P. Note: 1K (KiB) = 1024B. |
|
--no-progress |
/ |
Do not display the progress bar. |
|
--page-size |
int |
Maximum number of objects listed per page during batch upload. Default value: 1000. Valid range: 1–1000. |
|
--parallel |
int |
Number of concurrent tasks for internal operations on a single file. |
|
--part-size |
SizeSuffix |
Part size for multipart upload. By default, ossutil calculates an appropriate part size based on the file size. Valid range: 100 KiB–5 GiB. |
|
-r, --recursive |
/ |
Perform the operation recursively. When this option is specified, the command operates on all matching objects in the bucket. Otherwise, it operates only on the object specified by the path. |
|
--request-payer |
string |
Payment method for the request. Set this parameter if the bucket uses pay-by-requester mode. Valid value: requester. |
|
--size-only |
/ |
Upload only source files whose size differs from the destination files. |
|
--storage-class |
string |
Storage class of the object. Valid values:
|
|
--tagging |
strings |
Tags for the object, in key=value format. |
|
--tagging-directive |
string |
Specifies how to set tags for the destination object. Valid values:
|
|
-u, --update |
/ |
Skip files that already exist at the destination and have a newer modification time than the source files. Note
If a file already exists at the destination but has an older modification time than the source file, the file is updated. |
|
--ignore-existing |
/ |
Skip files that already exist at the destination. |
Starting from ossutil 2.3.0, the --job, --parallel, --bigfile-threshold, --part-size, and --write-buffer-size options can be configured through a configuration file. Append them in key=value format (for example, job=10) in the corresponding profile section of the configuration file, or set them using ossutil config set. Command-line options take precedence over configuration file settings.
For more information, see Command-line options.
Object naming rules are as follows:
-
For single-file upload, if the prefix is empty, the object name is the file name.
-
For single-file upload, if the prefix ends with "/", the object name is prefix + file name.
-
For batch upload, if the prefix is empty, the object name is the relative path of the source file.
-
For batch upload, if the prefix ends with "/", the object name is prefix + relative path of the source file.
-
For batch upload, if the prefix does not end with "/", the object name is prefix + "/" + relative path of the source file.
The relative path of a source file starts after the root directory. For example, when running cp /root/dir/ ..., the relative path of the file /root/dir/subdir/test.txt is subdir/test.txt.
Examples
Upload a single file
-
Upload a single file
Upload the local file examplefile.txt to the desfolder folder in examplebucket.
ossutil cp D:/localpath/examplefile.txt oss://examplebucket/desfolder/
Upload multiple files
-
Upload only files in a folder
Upload files from the local folder localfolder to the desfolder folder in examplebucket.
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ -
Batch upload files that match a condition
Upload all files with the TXT file format.
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ --include "*.txt" -
Use 10 concurrent tasks for batch upload
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ -f -j 10
Throttle upload speed
-
Upload the local file upload.rar to the desfolder folder in examplebucket at 20 MB/s. The default unit is bytes per second (B/s).
ossutil cp D:/upload.rar oss://examplebucket/desfolder/ --bandwidth-limit 20971520 -
Upload the local file file.rar to the desfolder folder in examplebucket, limiting the upload speed to 50 MB/s. Specify the unit as megabytes per second (MB/s).
ossutil cp D:/file.rar oss://examplebucket/desfolder/ --bandwidth-limit 50M