mirror of
https://github.com/grocy/grocy.git
synced 2026-04-03 11:26:16 +02:00
Adapt code style / use up to date reasonable chunk size
This commit is contained in:
parent
160b0ea9eb
commit
e0f588fc06
|
|
@ -110,24 +110,25 @@ class FilesApiController extends BaseApiController
|
||||||
|
|
||||||
$fileName = $this->checkFileName($args['fileName']);
|
$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();
|
$requestBody = $request->getBody();
|
||||||
|
while ($data = $requestBody->read(1048576))
|
||||||
while ($data = $requestBody->read(32768))
|
|
||||||
{
|
{
|
||||||
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);
|
return $this->EmptyApiResponse($response);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user