mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-13 07:29:39 +00:00
Storage/S3: Override get_local_path method
This commit is contained in:
parent
65e99933a7
commit
09bc16ecef
@ -16,10 +16,15 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from contextlib import contextmanager
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
import boto3
|
||||
|
||||
from indico.core import signals
|
||||
from indico.core.config import config
|
||||
from indico.core.plugins import IndicoPlugin
|
||||
from indico.core.storage import Storage
|
||||
from indico.core import signals
|
||||
from indico.web.flask.util import send_file
|
||||
|
||||
|
||||
@ -57,6 +62,13 @@ class S3Storage(Storage):
|
||||
def open(self, file_id):
|
||||
return self.client.get_object(Bucket=self.bucket, Key=file_id)['Body']
|
||||
|
||||
@contextmanager
|
||||
def get_local_path(self, file_id):
|
||||
with NamedTemporaryFile(suffix='indico.tmp', dir=config.TEMP_DIR) as tmpfile:
|
||||
self._copy_file(self.open(file_id), tmpfile)
|
||||
tmpfile.flush()
|
||||
yield tmpfile.name
|
||||
|
||||
def save(self, name, content_type, filename, fileobj):
|
||||
self.client.upload_fileobj(fileobj, self.bucket, name)
|
||||
return name, ''
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user