如何使用python的请求包从oracle云存储经典容器下载文件夹的内容?

时间:2022-01-03 15:28:25

I have a folder named 'test1' inside the container 'test' (/test/test1/).
How do I download the objects using this prefix in requests package for python?

我在容器'test'(/ test / test1 /)中有一个名为'test1'的文件夹。如何在python的请求包中使用此前缀下载对象?

For downloading a file under container, I've the following code:

要下载容器下的文件,我有以下代码:

def download_file_oraclecloud(self,
                              ora_url,
                              username,
                              password,
                              container_name,
                              file_name,
                              local_file_name,
                              url) :

    # url='https://storage.us2.oraclecloud.com/v1/Storage-a428615/'
    token = self.create_session_oraclecloud(ora_url,username,password)
    headers= {
        'X-Auth-Token':token,
    }
    response=requests.get(url+container_name+'/'+file_name,open(local_file_name, 'wb'),headers=headers)

How can I download the contents of a folder?

如何下载文件夹的内容?

1 个解决方案

#1


0  

The object store does have a REST API docs here

对象存储在这里有一个REST API文档

  1. get your username, password, and your auth url (it should end in auth/v1.0)
  2. 获取您的用户名,密码和您的身份验证URL(它应以auth / v1.0结尾)

  3. send a get request to the auth url with your username and password as headers
  4. 使用您的用户名和密码作为标头向auth网址发送获取请求

  5. save the X-Auth-Token from the response
  6. 从响应中保存X-Auth-Token

  7. make a get request for the objects you'd like to download see this doc
  8. 对您要下载的对象发出get请求,请参阅此文档

This blog post provides a pretty good walk-through too
https://blogs.oracle.com/solaris/playing-around-with-the-oracle-storage-cloud-service-v2

这个博客文章提供了一个非常好的演练过程https://blogs.oracle.com/solaris/playing-around-with-the-oracle-storage-cloud-service-v2

#1


0  

The object store does have a REST API docs here

对象存储在这里有一个REST API文档

  1. get your username, password, and your auth url (it should end in auth/v1.0)
  2. 获取您的用户名,密码和您的身份验证URL(它应以auth / v1.0结尾)

  3. send a get request to the auth url with your username and password as headers
  4. 使用您的用户名和密码作为标头向auth网址发送获取请求

  5. save the X-Auth-Token from the response
  6. 从响应中保存X-Auth-Token

  7. make a get request for the objects you'd like to download see this doc
  8. 对您要下载的对象发出get请求,请参阅此文档

This blog post provides a pretty good walk-through too
https://blogs.oracle.com/solaris/playing-around-with-the-oracle-storage-cloud-service-v2

这个博客文章提供了一个非常好的演练过程https://blogs.oracle.com/solaris/playing-around-with-the-oracle-storage-cloud-service-v2