Compared with common file systems, data in Object Storage Service (OSS) is stored as objects in a flat structure instead of a hierarchical structure. All data in OSS is stored as objects in buckets. However, OSS supports directories as a concept to group objects and simplify management. In the OSS console, a directory is an object whose name ends with a forward slash (/), which is similar to a directory in Windows. This topic describes how to upload directories to and download directories from OSS.
Use the OSS console
- Upload a directory: When you upload a directory, drag the directory to the upload section. The directory structure is retained. For more information, see Upload objects.
- Download a directory: The OSS console does not support direct download of directories. You can download multiple objects from a bucket to the specified directory that is created on the local computer. For more information, see Download objects.
Use OSS SDKs
- Upload a directory: OSS SDKs do not support direct upload of directories. To upload multiple objects to the same directory, specify the same prefix for the objects that you want to upload and separate the prefix and the object names with forward slashes (/). For example, you want to upload the example1.txt, example2.txt, and example3.txt local files to the dir directory. In this example, OSS SDK for Java is used. You must set the object names to dir/example1.txt, dir/example2.txt, and dir/example3.txt during upload.
- Download a directory: OSS SDKs do not support direct download of directories. However, you can download multiple objects to the same local directory. For example, you want to download all objects stored in a directory named folder from a bucket to a local directory named local.
- When you know the objects stored in the folder directory
For example, the folder directory contains two objects: example1.jpg and example2.jpg. In this example, OSS SDK for Java is used. You must set the object names to folder/example1.jpg and folder/example2.jpg and the local paths to local/folder/example1.jpg and local/folder/example2.jpg when you download the objects in the directory.
- When you do not know the objects stored in the folder directory
- Query all objects in the folder directory by calling the ListObjects (GetBucket) operation.
- Specify the object names and the full local paths respectively based on the preceding method.
- When you know the objects stored in the folder directory
For more information about the sample code that you can use to upload directories to and download directories from OSS by using OSS SDKs for various programming languages, see Overview.
Use ossbrowser
- Upload a directory: In the specified bucket or directory, click Folder and select the directory that you want to upload. You can also drag the directory to ossbrowser. For more information, see Use ossbrowser.
- Download a directory: Click Download in the Actions column of the directory. For more information, see Use ossbrowser.
Use ossutil
- Upload a directory: Specify the -r option when you upload a directory. For more information, see Upload objects.
- Download a directory: Specify the -r option when you download a directory. For more information, see Download objects.