mirror of
https://github.com/matrix-org/synapse-s3-storage-provider.git
synced 2024-10-23 07:29:40 +00:00
Merge pull request #2 from matrix-org/erikj/upload
Implement uploading of files to s3
This commit is contained in:
commit
303b9690c6
1 changed files with 10 additions and 3 deletions
|
@ -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"""
|
||||||
|
|
Loading…
Reference in a new issue