簡體   English   中英

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

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

該文檔說明了創建容器的方法,但是沒有關於如何下載和上傳文件的API的解釋,單個文件不是一堆文件。 我要尋找的語言是Python3。

您可以嘗試此代碼,該代碼對我有用,可以上傳到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)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM