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.
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 | Reads 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 is run on all matching objects in the bucket. Otherwise, the command is run 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 | / | Uploads only source files whose sizes are different from the destination files. |
--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 | / | Uploads only source files that are newer than the destination files. |
--ignore-existing | / | Skips destination files that already exist. |
For more information, see Command-line options.
The naming conventions for destination objects are as follows:
When you upload a single file:
If the prefix is empty, the object name is the file name.
If the prefix ends with a forward slash (/), the object name is prefix + file name.
When you perform a batch upload:
If the prefix is empty, the object name is the relative path of the source file.
If the prefix ends with a forward slash (/), the object name is prefix + relative path of the source file.
If the prefix does not end with a forward slash (/), the object name is prefix + / + relative path of the source file.
The relative path of a source file is the name that follows the root directory. For example, when you run cp /root/dir/ ..., 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 to a specified directory:
ossutil cp D:/localpath/examplefile.txt oss://examplebucket/desfolder/
Upload multiple files
Upload a local directory to a specified OSS directory:
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/Upload all files in 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
Limit upload speed to 20 MB/s (specified in B/s):
ossutil cp D:/upload.rar oss://examplebucket/desfolder/ --bandwidth-limit 20971520Upload a file with a 50 MB/s bandwidth limit:
ossutil cp D:/file.rar oss://examplebucket/desfolder/ -r --bandwidth-limit 50M