Merge pull request #2 from matrix-org/erikj/upload

Implement uploading of files to s3
This commit is contained in:
Erik Johnston 2018-02-13 13:58:51 +00:00 committed by GitHub
commit 303b9690c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,6 +25,7 @@ import boto3
import botocore import botocore
import logging import logging
import threading import threading
import os
logger = logging.getLogger("synapse.s3") logger = logging.getLogger("synapse.s3")
@ -41,12 +42,18 @@ class S3StorageProviderBackend(StorageProvider):
self.cache_directory = hs.config.media_store_path self.cache_directory = hs.config.media_store_path
self.bucket = config self.bucket = config
self.s3 = boto3.client('s3')
def store_file(self, path, file_info): def store_file(self, path, file_info):
"""See StorageProvider.store_file""" """See StorageProvider.store_file"""
pass def _store_file():
with open(os.path.join(self.cache_directory, path), 'rb') as f:
boto3.resource('s3').Bucket(self.bucket).put_object(
Key=path, Body=f,
)
return make_deferred_yieldable(
reactor.callInThread(_store_file)
)
def fetch(self, path, file_info): def fetch(self, path, file_info):
"""See StorageProvider.fetch""" """See StorageProvider.fetch"""