public function upload(Base $base, $randomize = true) { $file = $base->getFile(); if (!$file instanceof UploadedFile) { throw new \InvalidArgumentException('There is no file to upload!'); } $fileName = $this->generateFilename($file, $randomize); $fs = new Filesystem(); try { $fs->mkdir($this->directory, 0777); $file->move($this->directory, $fileName); } catch (IOExceptionInterface $e) { throw new IOException($e->getMessage()); } catch (FileException $e) { throw new FileException($e->getMessage()); } catch (\Exception $e) { throw new Exception($e->getMessage()); } $base->setPath($fileName); return $fileName; }