From 66e2ad46be370c3d24ae78ba90f1fa2453307d8e Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 23 Sep 2026 17:20:36 +0200 Subject: [PATCH 1/2] fix: improve mimetype detection when serving a task output file (just like when saving and generating a preview) Signed-off-by: Julien Veyssier --- lib/Controller/AssistantApiController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Controller/AssistantApiController.php b/lib/Controller/AssistantApiController.php index 7d876129a..61d2c2537 100644 --- a/lib/Controller/AssistantApiController.php +++ b/lib/Controller/AssistantApiController.php @@ -399,7 +399,8 @@ public function getOutputFilePreview(int $ocpTaskId, int $fileId, ?int $x = 100, public function getOutputFile(int $ocpTaskId, int $fileId): DataDownloadResponse|DataResponse { try { $taskOutputFile = $this->assistantService->getTaskOutputFile($this->userId, $ocpTaskId, $fileId); - $realMime = mime_content_type($taskOutputFile->fopen('rb')); + $head = fread($taskOutputFile->fopen('rb'), 4096); + $realMime = (new \finfo(FILEINFO_MIME_TYPE))->buffer($head); $response = new DataDownloadResponse( $taskOutputFile->getContent(), $ocpTaskId . '-' . $fileId, From 5cde2e7943d9b9799ce5750f0bebb92f94656028 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 24 Sep 2026 15:29:46 +0200 Subject: [PATCH 2/2] use the appData file extension if there is one Signed-off-by: Julien Veyssier --- lib/Controller/AssistantApiController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Controller/AssistantApiController.php b/lib/Controller/AssistantApiController.php index 61d2c2537..6ac2e090f 100644 --- a/lib/Controller/AssistantApiController.php +++ b/lib/Controller/AssistantApiController.php @@ -401,9 +401,16 @@ public function getOutputFile(int $ocpTaskId, int $fileId): DataDownloadResponse $taskOutputFile = $this->assistantService->getTaskOutputFile($this->userId, $ocpTaskId, $fileId); $head = fread($taskOutputFile->fopen('rb'), 4096); $realMime = (new \finfo(FILEINFO_MIME_TYPE))->buffer($head); + + $fileName = $ocpTaskId . '-' . $fileId; + $extension = pathinfo($taskOutputFile->getName(), PATHINFO_EXTENSION); + if ($extension !== '') { + $fileName .= '.' . $extension; + } + $response = new DataDownloadResponse( $taskOutputFile->getContent(), - $ocpTaskId . '-' . $fileId, + $fileName, $realMime ?: 'application/octet-stream', ); $response->cacheFor(60 * 60 * 24, false, true);