mirror of
https://github.com/grocy/grocy.git
synced 2025-08-17 11:06:36 +00:00
Stream files directly from disk (instead of loading them completely in memory first)
This commit is contained in:
@@ -6,6 +6,7 @@ use Grocy\Services\FilesService;
|
|||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Slim\Exception\HttpNotFoundException;
|
use Slim\Exception\HttpNotFoundException;
|
||||||
|
use Slim\Psr7\Stream;
|
||||||
|
|
||||||
class FilesApiController extends BaseApiController
|
class FilesApiController extends BaseApiController
|
||||||
{
|
{
|
||||||
@@ -51,10 +52,10 @@ class FilesApiController extends BaseApiController
|
|||||||
|
|
||||||
if (file_exists($filePath))
|
if (file_exists($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));
|
||||||
return $response->withHeader('Content-Disposition', 'inline; filename="' . $fileName . '"');
|
$response = $response->withHeader('Content-Disposition', 'inline; filename="' . $fileName . '"');
|
||||||
|
return $response->withBody(new Stream(fopen($filePath, 'rb')));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -82,10 +83,10 @@ class FilesApiController extends BaseApiController
|
|||||||
|
|
||||||
if (file_exists($filePath))
|
if (file_exists($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));
|
||||||
return $response->withHeader('Content-Disposition', 'inline; filename="' . $fileName . '"');
|
$response = $response->withHeader('Content-Disposition', 'inline; filename="' . $fileName . '"');
|
||||||
|
return $response->withBody(new Stream(fopen($filePath, 'rb')));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user