X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdropzonejs%2Fsrc%2FController%2FUploadController.php;fp=web%2Fmodules%2Fcontrib%2Fdropzonejs%2Fsrc%2FController%2FUploadController.php;h=fb08090c047f5d1adfd2bb358fa07de9d2c8a5fe;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/dropzonejs/src/Controller/UploadController.php b/web/modules/contrib/dropzonejs/src/Controller/UploadController.php new file mode 100644 index 000000000..fb08090c0 --- /dev/null +++ b/web/modules/contrib/dropzonejs/src/Controller/UploadController.php @@ -0,0 +1,80 @@ +uploadHandler = $upload_handler; + $this->request = $request; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('dropzonejs.upload_handler'), + $container->get('request_stack')->getCurrentRequest() + ); + } + + /** + * Handles DropzoneJs uploads. + */ + public function handleUploads() { + $file = $this->request->files->get('file'); + if (!$file instanceof UploadedFile) { + throw new AccessDeniedHttpException(); + } + + // @todo: Implement file_validate_size(); + try { + // Return JSON-RPC response. + return new AjaxResponse([ + 'jsonrpc' => '2.0', + 'result' => basename($this->uploadHandler->handleUpload($file)), + 'id' => 'id', + ]); + } + catch (UploadException $e) { + return $e->getErrorResponse(); + } + } + +}