This topic describes how to download an object to a local file.
The following code provides an example on how to download a specified object from OSS to a local file:
# -*- coding: utf-8 -*- import oss2 # Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create your RAM user, log on to the RAM console. auth = oss2.Auth('<yourAccessKeyId>', '<yourAccessKeySecret>') # The endpoint of the China (Hangzhou) region is used in this example. Specify the actual endpoint. bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>') # Download an object to a local file. If the name of the object is the same as that of the local file, the object replaces the local file. Otherwise, the object is downloaded as a new local file. # <yourLocalFile> consists of the path, name, and extension of the local file. Example: /users/local/myfile.txt. # <yourObjectName> specifies the complete path of the object to download from OSS, and must include the file extension of the object. Example: abc/efg/123.jpg. bucket.get_object_to_file('<yourObjectName>', '<yourLocalFile>')