使用python将oss文件下载本地

将oss文件下载到本地方法如下:

    def download(self, remote_file, local_file):
        # if_access_bucket = oss2.Bucket(self.auth, config['OSS_CONFIG']['endpoint'],'if-access')
        local_path = os.path.dirname(local_file)
        if local_path and not os.path.exists(local_path):
            os.makedirs(local_path)

        res = self.bucket.get_object_to_file(remote_file, local_file)
        return res

注意:
比如oss文件上的目录为 oss://bucket-sunkaidi/home/dc/data.gz,其中bucket-sunkaidi为bucket名称,如果需要将data.gz文件下载下来remote_file需要传入的是home/dc/data.gz,而不是/home/dc/data.gz

猜你喜欢

转载自blog.csdn.net/weixin_38653290/article/details/89680072