diff --git a/app/controllers/storage.php b/app/controllers/storage.php index eaf8bef3c..b6e6c2c1b 100644 --- a/app/controllers/storage.php +++ b/app/controllers/storage.php @@ -468,8 +468,12 @@ $utopia->post('/v1/storage/files') $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); $data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag); - $sizeCompressed = (int) $device->write($path, $data); + if(!$device->write($path, $data)) { + throw new Exception('Failed to save file', 500); + } + $sizeActual = $device->getFileSize($path); + $file = $projectDB->createDocument([ '$collection' => Database::SYSTEM_COLLECTION_FILES, '$permissions' => [ @@ -483,7 +487,7 @@ $utopia->post('/v1/storage/files') 'signature' => $device->getFileHash($path), 'mimeType' => $mimeType, 'sizeOriginal' => $size, - 'sizeCompressed' => $sizeCompressed, + 'sizeActual' => $sizeActual, 'algorithm' => $compressor->getName(), 'token' => bin2hex(random_bytes(64)), 'comment' => '', @@ -503,7 +507,7 @@ $utopia->post('/v1/storage/files') ; $usage - ->setParam('storage', $sizeCompressed) + ->setParam('storage', $sizeActual) ; $list[] = $file->getArrayCopy(); diff --git a/tests/e2e/ProjectStorageTest.php b/tests/e2e/ProjectStorageTest.php index d9b7c7148..6192fd93c 100644 --- a/tests/e2e/ProjectStorageTest.php +++ b/tests/e2e/ProjectStorageTest.php @@ -28,12 +28,19 @@ class ProjectStorafeTest extends BaseProjects 'folderId' => 'xyz', ]); + $this->assertEquals($file['headers']['status-code'], 201); $this->assertNotEmpty($file['body'][0]['$uid']); $this->assertEquals('files', $file['body'][0]['$collection']); $this->assertIsInt($file['body'][0]['dateCreated']); $this->assertEquals('logo.png', $file['body'][0]['name']); $this->assertEquals('image/png', $file['body'][0]['mimeType']); $this->assertEquals(47218, $file['body'][0]['sizeOriginal']); + $this->assertEquals(54944, $file['body'][0]['sizeActual']); + $this->assertEquals('gzip', $file['body'][0]['algorithm']); + $this->assertEquals('1', $file['body'][0]['fileOpenSSLVersion']); + $this->assertEquals('aes-128-gcm', $file['body'][0]['fileOpenSSLCipher']); + $this->assertNotEmpty($file['body'][0]['fileOpenSSLTag']); + $this->assertNotEmpty($file['body'][0]['fileOpenSSLIV']); return $data; }