Adapt code style / use up to date reasonable chunk size

This commit is contained in:
Bernd Bestel 2024-02-23 17:53:14 +01:00
parent 160b0ea9eb
commit e0f588fc06
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300

View File

@ -110,24 +110,25 @@ class FilesApiController extends BaseApiController
$fileName = $this->checkFileName($args['fileName']);
if(false === $fileHandle = fopen($this->getFilesService()->GetFilePath($args['group'], $fileName), 'xb'))
$fileHandle = fopen($this->getFilesService()->GetFilePath($args['group'], $fileName), 'xb');
if($fileHandle === false)
{
throw new \Exception('Cannot create file');
throw new \Exception("Error while creating file $fileName");
}
// Save the file to disk in chunks of 1 MB
$requestBody = $request->getBody();
while ($data = $requestBody->read(32768))
while ($data = $requestBody->read(1048576))
{
if ( fwrite($fileHandle, $data) === false )
if (fwrite($fileHandle, $data) === false)
{
throw new \Exception('Cannot write to file');
throw new \Exception("Error while writing file $fileName");
}
}
if ( fclose($fileHandle) === false )
if (fclose($fileHandle) === false)
{
throw new \Exception('Failed to close file');
throw new \Exception("Error while closing file $fileName");
}
return $this->EmptyApiResponse($response);