From fc31d79935a350e15930cf299dcc400419a2d619 Mon Sep 17 00:00:00 2001 From: Daniele Maccioni Date: Tue, 31 Jan 2017 21:05:46 +0100 Subject: [PATCH] Added upload and upload_file. --- s3archive/s3archive.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/s3archive/s3archive.py b/s3archive/s3archive.py index 0e4be88..2f6ca15 100644 --- a/s3archive/s3archive.py +++ b/s3archive/s3archive.py @@ -30,3 +30,14 @@ def find(self, regex): def exists(self, regex): """Returns False if there are no matches for the given regex.""" return bool(next(self.find(regex), None)) + + def upload(self, source, destination): + """Uploads a file from the given source to the given destination on S3.""" + self.upload_file(open(source, 'rb'), destination) + + def upload_file(self, file_object, destination): + """Uploads a file to S3 with the given destination.""" + self.bucket.put_object( + Key=destination, + Body=file_object, + )