summaryrefslogtreecommitdiff
path: root/fbin/file_storage/filesystem.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2019-08-17 15:17:02 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2019-08-17 15:19:36 +0200
commit13d38291bd07401bd16b6e6805edc72bf0029b2f (patch)
tree2f550185745df9ffb219b468fc1e33447b5a7a22 /fbin/file_storage/filesystem.py
parentce47bae559df59be8d8b2016cefa62c2fa00d0e2 (diff)
Fetch and store thumbnails via storage modules
This will allow us to remotely store thumbnails in case of S3. For S3 the thumb bucket is configurable to allow these to be stored separately. The S3 key for thumbnails does not conflict with files, so these can be stored in the same bucket if needed.
Diffstat (limited to 'fbin/file_storage/filesystem.py')
-rw-r--r--fbin/file_storage/filesystem.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/fbin/file_storage/filesystem.py b/fbin/file_storage/filesystem.py
index 3b46e34..1259002 100644
--- a/fbin/file_storage/filesystem.py
+++ b/fbin/file_storage/filesystem.py
@@ -8,6 +8,7 @@ class Storage(BaseStorage):
def __init__(self, app):
super().__init__(app)
os.makedirs(self.app.config['FILE_DIRECTORY'], exist_ok=True)
+ os.makedirs(self.app.config['THUMB_DIRECTORY'], exist_ok=True)
def store_file(self, uploaded_file, file_hash, user, ip):
size = uploaded_file.content_length
@@ -45,3 +46,17 @@ class Storage(BaseStorage):
def temp_file(self, f):
with open(f.get_path(), 'rb') as f:
yield f
+
+ def get_thumbnail(self, f):
+ path = f.get_thumb_path()
+ if not os.path.exists(path):
+ return
+ return path
+
+ def store_thumbnail(self, f, stream):
+ path = f.get_thumb_path()
+ with open(path, 'wb') as f:
+ buf = stream.read(1024*10)
+ while buf:
+ f.write(buf)
+ buf = stream.read(1024*10)