RYMCU

🐛 华为云文件下载

# 🐛划水 # 划水 # 🐛

所属作品集

🐛
上代码,需要安装 esdk-obs-python
命令行执行: pip install esdk-obs-python;

# -*- coding: utf-8 -*-
from obs import ObsClient

marker = '1'
baseLocalPath="./file2/" # 下载到本地的文件目录
bucketName = 'bucketName' # 需要改为自己的buckenName
hw_iam_ak = "hw_obs_ak" # 华为云iam账户ak
hw_iam_sk = "hw_obs_ak" # 华为云iam账户ak
hw_obs_server= "hw_obs_server" # 华为云obs地区,如: https://obs.cn-east-1.myhuaweicloud.com
obsClient = ObsClient(
    access_key_id='hw_iam_ak',
    secret_access_key='hw_iam_sk',
    server='hw_obs_server'  #地区
)



def get_all():
    global marker

    while marker:
        if marker == '1':
            marker = None
        # 列举出桶名为buckenName下的所有文件对象    
        resp = obsClient.listObjects(bucketName,marker=marker)
        if resp.status < 300:
            index = 1
            for content in resp.body.contents:
                localFilePath = baseLocalPath + content.key
                print(content.key)
                
                # 下载文件到本地
                obsClient.getObject(bucketName, content.key, downloadPath=localFilePath)
            marker = resp.body.next_marker
        else:
            print('errorCode:', resp.errorCode)
            print('errorMessage:', resp.errorMessage)

if __name__ == '__main__':
    get_all()

所属作品集

后发布评论