mirror of
https://github.com/grocy/grocy.git
synced 2026-03-27 23:29:25 +01:00
Stream uploads to file
This commit is contained in:
parent
edf973df00
commit
160b0ea9eb
|
|
@ -109,9 +109,26 @@ class FilesApiController extends BaseApiController
|
|||
}
|
||||
|
||||
$fileName = $this->checkFileName($args['fileName']);
|
||||
$data = $request->getBody()->getContents();
|
||||
|
||||
file_put_contents($this->getFilesService()->GetFilePath($args['group'], $fileName), $data);
|
||||
if(false === $fileHandle = fopen($this->getFilesService()->GetFilePath($args['group'], $fileName), 'xb'))
|
||||
{
|
||||
throw new \Exception('Cannot create file');
|
||||
}
|
||||
|
||||
$requestBody = $request->getBody();
|
||||
|
||||
while ($data = $requestBody->read(32768))
|
||||
{
|
||||
if ( fwrite($fileHandle, $data) === false )
|
||||
{
|
||||
throw new \Exception('Cannot write to file');
|
||||
}
|
||||
}
|
||||
|
||||
if ( fclose($fileHandle) === false )
|
||||
{
|
||||
throw new \Exception('Failed to close file');
|
||||
}
|
||||
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user