Use the ossutil cp command to upload local resources such as files, images, and videos to OSS. You can also use this command to upload large files.
Usage notes
-
To upload files, you must have the
oss:PutObject,oss:ListParts, andoss:AbortMultipartUploadpermissions. For more information, see Grant custom access policies to RAM users. -
Batch upload is supported only when the source is a directory.
-
When you use the
-u, --updateoption, ossutil sends at least one HEAD request for each file to compare timestamps, even if the destination file does not exist. In scenarios where few files change, this generates many inefficient requests. This may reduce performance and result in additional request fees. Evaluate your business needs before you use this option. Use it only when necessary to avoid unnecessary resource consumption.
Command format
ossutil cp source dest [flags]
|
Parameter |
Type |
Description |
|
source |
string |
The path of the local file. Relative paths, absolute paths, and |
|
dest |
string |
The path of the object in the destination bucket. Example: |
|
--acl |
string |
The access permissions of the object. Valid values:
|
|
--bandwidth-limit |
SizeSuffix |
Limits the network bandwidth to control the data transfer rate. The minimum value is 1024 B/s. The default unit is B/s. When you configure this parameter, specify a unit for the bandwidth value as needed. Valid units include B (bytes), K (kilobytes), M (megabytes), and G (gigabytes). For example, 50 M specifies a bandwidth limit of 50 MB/s. |
|
--bigfile-threshold |
SizeSuffix |
The threshold to enable multipart upload, download, or copy for large files. The default value is 104857600. |
|
--cache-control |
string |
Specifies the caching behavior of the webpage when the object is downloaded. |
|
--content-disposition |
string |
Specifies how the object is displayed. |
|
--content-encoding |
string |
Declares the encoding method of the object. |
|
--content-type |
string |
The content type of the object. |
|
--copy-props |
string |
Determines which properties are uploaded from the source object. Valid values:
|
|
--checkpoint-dir |
string |
|
|
-d, --dirs |
string |
Returns the files and subdirectories in the current directory, instead of recursively displaying all files in all subdirectories. |
|
--encoding-type |
string |
The encoding type of the input object name or file name. Valid value: url. |
|
--end-with |
string |
Filters objects to include only those whose names are alphabetically before or at the specified value. |
|
--exclude |
stringArray |
The exclusion rules for paths or file names. |
|
--exclude-from |
stringArray |
Reads exclusion rules from a rule file. |
|
--expires |
stringArray |
Specifies the absolute expiration time for the cached content. |
|
--files-from |
stringArray |
Reads a list of source file names from a file. Empty lines or comment lines are ignored. |
|
--files-from-raw |
stringArray |
Reads a list of source file names from a file. |
|
--filter |
stringArray |
The filtering rules for paths or file names. |
|
--filter-from |
stringArray |
Reads filtering rules from a rule file. |
|
-f, --force |
/ |
Forces the operation without a confirmation prompt. |
|
--include |
stringArray |
The inclusion rules for paths or file names. Note
For more information about filtering options, see Filtering options. |
|
--include-from |
stringArray |
Reads inclusion rules from a rule file. |
|
-j, --job |
int |
The number of concurrent tasks. The default value is 3. Note
This parameter takes effect only when you specify the |
|
--listObjects |
/ |
Uses the ListObjects API operation to list objects. |
|
--max-size |
SizeSuffix |
The maximum size of a file to transfer. The default unit is byte. You can also use suffixes such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
|
--metadata |
strings |
Specifies the user metadata of the object. Use the key=value format. |
|
--metadata-directive |
string |
Specifies how to set the metadata of the destination object. Valid values:
|
--metadata-exclude | stringArray | The exclusion rules for object metadata. |
--metadata-filter | stringArray | The filtering rules for object metadata. |
--metadata-filter-from | stringArray | Read object metadata filtering rules from a rule file. |
--metadata-include | stringArray | The inclusion rules for object metadata. |
--min-age |
Duration |
Uploads only files modified before the specified time interval. The default unit is second. You can use a suffix for the unit. For example, 1h specifies 1 hour. Note
|
|
--max-age |
Duration |
Uploads only files modified within the specified time interval. The default unit is second. You can use a suffix for the unit. For example, 1h specifies 1 hour. Note
|
|
--min-mtime |
Time |
Uploads only files modified after the specified time. The time must be in UTC format. Example: 2006-01-02T15:04:05. Note
|
|
--max-mtime |
Time |
Uploads only files modified before the specified time. The time must be in UTC format. Example: 2006-01-02T15:04:05. |
|
--min-size |
SizeSuffix |
The minimum size of a file to transfer. The default unit is byte. You can also use suffixes such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
|
--no-progress |
/ |
Does not display the progress bar. |
|
--page-size |
int |
The maximum number of objects to list per page during a batch upload. The default value is 1000. The value must be between 1 and 1000. |
|
--parallel |
int |
The number of concurrent tasks for operations on a single file. |
|
--part-size |
SizeSuffix |
The part size. By default, ossutil calculates an appropriate part size based on the file size. The value must be between 100 KiB and 5 GiB. |
|
-r, --recursive |
/ |
Performs the operation recursively. If you specify this option, the command runs on all matching objects in the bucket. Otherwise, the command runs only on the object specified by the path. |
|
--request-payer |
string |
The payment method for the request. Set this parameter if you use the pay-by-requester mode. Valid value: requester. |
|
--size-only |
/ |
Upload only source files that have different file sizes. |
|
--storage-class |
string |
The storage class of the object. Valid values:
|
|
--tagging |
strings |
Specifies the tags of the object. Use the key=value format. |
|
--tagging-directive |
string |
Specifies how to set the tags of the destination object. Valid values:
|
|
-u, --update |
/ |
Skips destination files that already exist and are newer than the source files. Note
If a destination file exists and has the same modification time as the source file, ossutil updates the destination file. |
|
--ignore-existing |
/ |
Skips destination files that already exist. |
For more information, see Command-line options.
The naming convention for object files is as follows:
-
When you upload a single file with an empty prefix, the object name is the same as the filename.
When uploading a single file, if the prefix ends with "/", the object name becomes prefix + filename.
-
For batch uploads, if the prefix is empty, the object name is the relative path of the source file.
For batch uploads, if the prefix ends with a forward slash (/), the object name is prefix + the relative path of the source file.
For batch uploads, if the prefix does not end with a forward slash (/), the object name is prefix + "/" + the relative path of the source file.
The relative path of a source file is the portion of its path that follows the specified root directory. For example, if you run the cp /root/dir/ ... command, the relative path of the file /root/dir/subdir/test.txt is subdir/test.txt.
Usage examples
Upload a single file
Upload a single file.
Upload the local file examplefile.txt to the desfolder folder in the bucket examplebucket.
ossutil cp D:/localpath/examplefile.txt oss://examplebucket/desfolder/
Upload multiple files
-
You can upload only the files within the folder.
Upload the files in the local folder localfolder to the desfolder folder in the bucket
examplebucket.ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ Batch upload files that match the specified criteria
Upload all files in the TXT format:
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ --include "*.txt"-
Use 10 concurrent tasks to batch upload files:
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ -f -j 10
Limit the upload speed
-
Upload the local file upload.rar to the desfolder folder in examplebucket at a rate of 20 MB/s. The default unit for the rate limit 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, and limit the upload speed to 50 MB/s.
ossutil cp D:/file.rar oss://examplebucket/desfolder/ -r --bandwidth-limit 50M