1818use Flowpack \Media \Ui \Tus \TusEventHandler ;
1919use Neos \Cache \Frontend \VariableFrontend ;
2020use Neos \Flow \Annotations as Flow ;
21+ use Neos \Flow \Utility \Environment ;
22+ use Neos \Flow \Utility \Exception ;
2123use Neos \Fusion \View \FusionView ;
2224use Neos \Neos \Controller \Module \AbstractModuleController ;
25+ use Neos \Utility \Exception \FilesException ;
26+ use Neos \Utility \Files ;
27+ use ReflectionException ;
2328use TusPhp \Events \TusEvent ;
2429use TusPhp \Tus \Server ;
2530
@@ -34,6 +39,12 @@ class MediaController extends AbstractModuleController
3439 */
3540 protected $ tusEventHandler ;
3641
42+ /**
43+ * @Flow\Inject
44+ * @var Environment
45+ */
46+ protected $ environment ;
47+
3748 /**
3849 * @var FusionView
3950 */
@@ -65,11 +76,20 @@ public function indexAction(): void
6576 }
6677
6778 /**
68- * @throws \ReflectionException
79+ * @throws Exception
80+ * @throws FilesException
81+ * @throws ReflectionException
6982 */
7083 public function uploadAction (): void
7184 {
85+ $ uploadDirectory = Files::concatenatePaths ([$ this ->environment ->getPathToTemporaryDirectory (), 'TusUpload ' ]);
86+ if (!file_exists ($ uploadDirectory )) {
87+ Files::createDirectoryRecursively ($ uploadDirectory );
88+ }
89+
7290 $ server = new Server ($ this ->partialUploadFileCacheAdapater );
91+ $ server ->setApiPath ($ this ->controllerContext ->getRequest ()->getHttpRequest ()->getUri ()->getPath ())
92+ ->setUploadDir ($ uploadDirectory );
7393 // @todo: Set upload dir to data/temporary
7494
7595 $ server ->event ()->addListener ('tus-server.upload.complete ' , function (TusEvent $ event ) {
0 commit comments