getTotalSize() public method

Get total file size in bytes
public getTotalSize ( ) : integer | null
return integer | null
 /**
  * Handle Image Upload
  *
  * @throws \Exception
  *
  * @return ApiFileService
  */
 private function handleImageUpload()
 {
     try {
         $config = new FlowConfig();
         $request = new FlowRequest();
         $basic = new Basic();
         $config->setTempDir(storage_path() . '/tmp');
         $config->setDeleteChunksOnSave(false);
         $totalSize = $request->getTotalSize();
         $uploadFile = $request->getFile();
         $fileName = md5($request->getFileName());
         $extension = explode('.', $request->getFileName())[1];
         $extraNumber = 1;
         if ($totalSize && $totalSize > 1024 * 1024 * 4) {
             throw new \Exception('File size exceeds 4MB', 400);
         }
         while ($this->isNameDuplicated($fileName . '.' . $extension, $this->location)) {
             $fileName = $fileName . $extraNumber;
             ++$extraNumber;
         }
         $fileName = $fileName . '.' . $extension;
         if ($basic->save($this->directory . $this->location . $fileName, $config, $request)) {
             $file = $this->handleImageSave($fileName, $this->location);
             return $file;
         }
         throw new \Exception('unable to save file', 500);
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage(), $e->getCode());
     }
 }
Beispiel #2
0
 /**
  * @covers ::__construct
  * @covers ::getParam
  * @covers ::getFileName
  * @covers ::getTotalSize
  * @covers ::getIdentifier
  * @covers ::getRelativePath
  * @covers ::getTotalChunks
  * @covers ::getDefaultChunkSize
  * @covers ::getCurrentChunkNumber
  * @covers ::getCurrentChunkSize
  * @covers ::getFile
  * @covers ::isFustyFlowRequest
  */
 public function testRequest_construct_withCustomRequest()
 {
     $request = new Request($this->requestArr);
     $this->assertSame('prettify.js', $request->getFileName());
     $this->assertSame(100, $request->getTotalSize());
     $this->assertSame('13632-prettifyjs', $request->getIdentifier());
     $this->assertSame('home/prettify.js', $request->getRelativePath());
     $this->assertSame(42, $request->getTotalChunks());
     $this->assertSame(1048576, $request->getDefaultChunkSize());
     $this->assertSame(1, $request->getCurrentChunkNumber());
     $this->assertSame(10, $request->getCurrentChunkSize());
     $this->assertSame(null, $request->getFile());
     $this->assertFalse($request->isFustyFlowRequest());
 }
Beispiel #3
0
 /**
  * @covers ::save
  */
 public function testFile_save_preProcess()
 {
     //// Setup test
     $this->requestArr['flowTotalChunks'] = 1;
     $this->requestArr['flowTotalSize'] = 10;
     $processCalled = false;
     $process = function ($chunk) use(&$processCalled) {
         $processCalled = true;
     };
     $this->config->setPreprocessCallback($process);
     $request = new Request($this->requestArr);
     $file = new File($this->config, $request);
     $chunkPrefix = sha1($request->getIdentifier()) . '_';
     $chunk = vfsStream::newFile($chunkPrefix . '1', 0777);
     $chunk->setContent('1234567890');
     $this->vfs->addChild($chunk);
     $filePath = $this->vfs->url() . DIRECTORY_SEPARATOR . 'file';
     //// Actual test
     $this->assertTrue($file->save($filePath));
     $this->assertTrue(file_exists($filePath));
     $this->assertEquals($request->getTotalSize(), filesize($filePath));
     $this->assertTrue($processCalled);
 }