Wasabi/S3-Objekt mit boto3 in Python in Datei herunterladen
English
Deutsch
Man kann boto3’s download_fileobj() verwenden, um Dateien von S3 auf das lokale Dateisystem herunterzuladen:
download_fileobj.py
with open("myfile.txt", "wb") as outfile:
my_bucket.download_fileobj("myfile.txt", outfile)Beachten, dass die Datei im Binärmodus ("wb") geöffnet werden muss.
Vollständiges Beispiel
download_boto3_example.py
import boto3
# Verbindung zu Wasabi / S3 herstellen
s3 = boto3.resource('s3',
endpoint_url = 'https://s3.eu-central-1.wasabisys.com',
aws_access_key_id = 'MY_ACCESS_KEY',
aws_secret_access_key = 'MY_SECRET_KEY'
)
# Bucket-Objekt abrufen
my_bucket = s3.Bucket('boto-test')
# Remote-Objekt "myfile.txt" als lokale Datei "test.txt" herunterladen
my_bucket.download_file("myfile.txt", "test.txt")Nicht vergessen, MY_ACCESS_KEY und MY_SECRET_KEY auszufüllen. Je nach Region und S3-kompatiblem Dienst muss möglicherweise eine andere Endpoint-URL anstelle von https://s3.eu-central-1.wasabisys.com verwendet werden.
Check out similar posts by category:
Allgemein
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow