/**
  * {@inheritdoc}
  */
 public function create(\SplFileInfo $rawFile, array $pathInfo, $destFsAlias)
 {
     if ($rawFile instanceof UploadedFile) {
         $size = $rawFile->getClientSize();
         $mimeType = $rawFile->getMimeType();
         $originalFilename = $rawFile->getClientOriginalName();
         $extension = $rawFile->getClientOriginalExtension();
     } else {
         $size = filesize($rawFile->getPathname());
         $mimeType = MimeTypeGuesser::getInstance()->guess($rawFile->getPathname());
         $originalFilename = $rawFile->getFilename();
         $extension = $rawFile->getExtension();
     }
     $file = new $this->fileClass();
     $file->setKey($pathInfo['path'] . $pathInfo['file_name']);
     $file->setGuid($pathInfo['guid']);
     $file->setMimeType($mimeType);
     $file->setOriginalFilename($originalFilename);
     $file->setSize($size);
     $file->setExtension($extension);
     $file->setStorage($destFsAlias);
     return $file;
 }
 public function attachFile(\SplFileInfo $file)
 {
     $content = $file->openFile('r')->fread($file->getSize());
     $extension = $file instanceof UploadedFile ? $file->getClientOriginalExtension() : $file->getExtension();
     $this->attachContent($content, $extension);
 }
 protected function saveToStorageAndGetFileEntity(\SplFileInfo $uploadedFile)
 {
     $hash = md5_file($uploadedFile->getRealPath());
     $folder1 = mb_substr($hash, 0, 2);
     $folder2 = mb_substr($hash, 2, 2);
     $folder3 = mb_substr($hash, 4, 2);
     $this->destinationFolder = "{$folder1}/{$folder2}/{$folder3}";
     $fileName = mb_substr($hash, 6) . ".{$uploadedFile->getClientOriginalExtension()}";
     $file = $this->convertSavedFileToEntity($uploadedFile, $fileName);
     $dir = "{$this->saveDirectory}/{$this->destinationFolder}";
     if (!file_exists("{$dir}/{$fileName}")) {
         mkdir($dir, 0777, true);
         $uploadedFile->move($dir, $fileName);
     }
     return $file;
 }