Make sure to clean the response before returning files

Was a problemw when returning images and there were leading empty lines in config.php which seem to get added to the response always...
This commit is contained in:
Bernd Bestel
2021-07-12 15:34:26 +02:00
parent 6659a5cd08
commit 2cc4f4d382
2 changed files with 3 additions and 0 deletions

View File

@@ -49,6 +49,7 @@ class CalendarApiController extends BaseApiController
$vCalendar->addEvent($vEvent); $vCalendar->addEvent($vEvent);
} }
ob_clean(); // Make sure to ONLY return the file
$response->write((new CalendarFactory())->createCalendar($vCalendar)); $response->write((new CalendarFactory())->createCalendar($vCalendar));
$response = $response->withHeader('Content-Type', 'text/calendar; charset=utf-8'); $response = $response->withHeader('Content-Type', 'text/calendar; charset=utf-8');
return $response->withHeader('Content-Disposition', 'attachment; filename="grocy.ics"'); return $response->withHeader('Content-Disposition', 'attachment; filename="grocy.ics"');

View File

@@ -49,6 +49,7 @@ class FilesApiController extends BaseApiController
if (file_exists($filePath)) if (file_exists($filePath))
{ {
ob_clean(); // Make sure to ONLY return the file
$response->write(file_get_contents($filePath)); $response->write(file_get_contents($filePath));
$response = $response->withHeader('Cache-Control', 'max-age=2592000'); $response = $response->withHeader('Cache-Control', 'max-age=2592000');
$response = $response->withHeader('Content-Type', mime_content_type($filePath)); $response = $response->withHeader('Content-Type', mime_content_type($filePath));
@@ -80,6 +81,7 @@ class FilesApiController extends BaseApiController
if (file_exists($filePath)) if (file_exists($filePath))
{ {
ob_clean(); // Make sure to ONLY return the file
$response->write(file_get_contents($filePath)); $response->write(file_get_contents($filePath));
$response = $response->withHeader('Cache-Control', 'max-age=2592000'); $response = $response->withHeader('Cache-Control', 'max-age=2592000');
$response = $response->withHeader('Content-Type', mime_content_type($filePath)); $response = $response->withHeader('Content-Type', mime_content_type($filePath));