implement dynamic file upload
This commit is contained in:
32
owrx/controllers/imageupload.py
Normal file
32
owrx/controllers/imageupload.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from owrx.controllers.assets import AssetsController
|
||||
from owrx.config import CoreConfig
|
||||
import uuid
|
||||
import json
|
||||
|
||||
|
||||
class ImageUploadController(AssetsController):
|
||||
def __init__(self, handler, request, options):
|
||||
super().__init__(handler, request, options)
|
||||
self.uuid = request.query["uuid"][0] if "uuid" in request.query else None
|
||||
self.id = request.query["id"][0] if "id" in request.query else None
|
||||
|
||||
def getFilePath(self, file=None):
|
||||
if self.uuid is None:
|
||||
raise FileNotFoundError("missing uuid")
|
||||
if self.id is None:
|
||||
raise FileNotFoundError("missing id")
|
||||
return "{tmp}/{file}-{uuid}".format(
|
||||
tmp=CoreConfig().get_temporary_directory(),
|
||||
file=self.id,
|
||||
uuid=self.uuid,
|
||||
)
|
||||
|
||||
def indexAction(self):
|
||||
self.serve_file(None)
|
||||
|
||||
def processImage(self):
|
||||
self.uuid = uuid.uuid4().hex
|
||||
contents = self.get_body()
|
||||
with open(self.getFilePath(), 'wb') as f:
|
||||
f.write(contents)
|
||||
self.send_response(json.dumps({"uuid": self.uuid}), content_type="application/json")
|
||||
Reference in New Issue
Block a user