diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 0e5d3f2846..7dd747b754 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -1127,9 +1127,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download') if ($size > APP_STORAGE_READ_BUFFER) { $response->addHeader('Content-Length', $device->getFileSize($path)); - $chunk = 2000000; // Max chunk of 2 mb - for ($i=0; $i < ceil($size / $chunk); $i++) { - $response->chunk($device->read($path, ($i * $chunk), min($chunk, $size - ($i * $chunk))), (($i + 1) * $chunk) >= $size); + for ($i=0; $i < ceil($size / MAX_OUTPUT_CHUNK_SIZE); $i++) { + $response->chunk($device->read($path, ($i * MAX_OUTPUT_CHUNK_SIZE), min(MAX_OUTPUT_CHUNK_SIZE, $size - ($i * MAX_OUTPUT_CHUNK_SIZE))), (($i + 1) * MAX_OUTPUT_CHUNK_SIZE) >= $size); } } else { $response->send($device->read($path)); diff --git a/app/init.php b/app/init.php index 0769e23a07..2b956762c9 100644 --- a/app/init.php +++ b/app/init.php @@ -103,6 +103,8 @@ const APP_AUTH_TYPE_SESSION = 'Session'; const APP_AUTH_TYPE_JWT = 'JWT'; const APP_AUTH_TYPE_KEY = 'Key'; const APP_AUTH_TYPE_ADMIN = 'Admin'; +// Response related +const MAX_OUTPUT_CHUNK_SIZE = 2*1024*1024; // 2MB $register = new Registry();