mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Added chunked output for large files
This commit is contained in:
@@ -75,14 +75,10 @@ App::post('/v1/storage/files')
|
||||
//throw new Exception('File type not allowed', 400);
|
||||
//}
|
||||
|
||||
// Check if file size is exceeding allowed limit
|
||||
if (!$fileSize->isValid($file['size'])) {
|
||||
if (!$fileSize->isValid($file['size'])) { // Check if file size is exceeding allowed limit
|
||||
throw new Exception('File size not allowed', 400);
|
||||
}
|
||||
|
||||
/*
|
||||
* Models
|
||||
*/
|
||||
$device = Storage::getDevice('local');
|
||||
|
||||
if (!$upload->isValid($file['tmp_name'])) {
|
||||
@@ -102,7 +98,6 @@ App::post('/v1/storage/files')
|
||||
if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
|
||||
$antiVirus = new Network('clamav', 3310);
|
||||
|
||||
// Check if file size is exceeding allowed limit
|
||||
if (!$antiVirus->fileScan($path)) {
|
||||
$device->delete($path);
|
||||
throw new Exception('Invalid file', 403);
|
||||
|
||||
@@ -13,6 +13,23 @@ class Response extends UtopiaResponse
|
||||
* @var SwooleResponse
|
||||
*/
|
||||
protected $swoole = null;
|
||||
|
||||
/**
|
||||
* Mime Types
|
||||
* with compression support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $compressed = [
|
||||
'text/plain' => true,
|
||||
'text/css' => true,
|
||||
'text/javascript' => true,
|
||||
'application/javascript' => true,
|
||||
'application/json' => true,
|
||||
'application/json; charset=UTF-8' => true,
|
||||
'image/svg+xml' => true,
|
||||
'application/xml+rss' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* Response constructor.
|
||||
@@ -43,9 +60,24 @@ class Response extends UtopiaResponse
|
||||
->appendHeaders()
|
||||
;
|
||||
|
||||
$this->size = $this->size + mb_strlen(implode("\n", $this->headers)) + mb_strlen($body, '8bit');
|
||||
$chunk = 2000000; // Max chunk of 2 mb
|
||||
$length = strlen($body);
|
||||
|
||||
$this->swoole->end($body);
|
||||
$this->size = $this->size + strlen(implode("\n", $this->headers)) + $length;
|
||||
|
||||
if(array_key_exists(
|
||||
$this->contentType,
|
||||
$this->compressed
|
||||
) && ($length <= $chunk)) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb
|
||||
$this->swoole->end($body);
|
||||
}
|
||||
else {
|
||||
for ($i=0; $i < ceil($length / $chunk); $i++) {
|
||||
$this->swoole->write(substr($body, ($i * $chunk), min((($i * $chunk) + $chunk), $length)));
|
||||
}
|
||||
|
||||
$this->swoole->end();
|
||||
}
|
||||
|
||||
$this->disablePayload();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user