简体   繁体   English

如何使用Python3使用Apache Libcloud在S3和GCS上下载和上传文件?

[英]How to download and upload files on S3 and GCS using Apache Libcloud using Python3?

The documentation states creating containers but no API has been explained as to how one can download and upload a file, single file not a bunch of them. 该文档说明了创建容器的方法,但是没有关于如何下载和上传文件的API的解释,单个文件不是一堆文件。 The language I am looking for is Python3. 我要寻找的语言是Python3。

You can try this code which works for me to upload to S3. 您可以尝试此代码,该代码对我有用,可以上传到S3。

from libcloud.storage.types import Provider
from libcloud.storage.providers import get_driver

FILE_PATH = 'test.txt'

cls = get_driver(Provider.S3)
driver = cls('api key', 'api secret key')

container = driver.get_container(container_name='testing-bucket')

extra = {'meta_data': {'owner': 'shakeel', 'created': '2014-02-2'}}

with open(FILE_PATH, 'rb') as iterator:
    obj = driver.upload_object_via_stream(iterator=iterator,
                                          container=container,
                                          object_name='test.txt',
                                          extra=extra)

source: https://libcloud.readthedocs.io/en/latest/storage/examples.html 来源: https : //libcloud.readthedocs.io/en/latest/storage/examples.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM