private function saveFile(MediaInterface $media)
    {
        $file = $media->getFile();

        $fileInfo = new FileInfo($file);
        $type = $fileInfo->getType();

        $media->setType($type);

        if ($media->getName() === null) {
            $media->setName($fileInfo->getName());
            $media->setAlt($fileInfo->getName());
        }

        $media
            ->setMimeType($fileInfo->getMimeType())
            ->setExtension($fileInfo->getExtension())
            ;

        if (!$this->createReference($media)) {
            return false;
        }

        $key = $this->originalDir.'/'.$media->getReference();
        $this->filesystemManipulator->save($key, $file->getPathname());

        $this->setSizeWidthAndHeight($media);

        $media->setFile();

        if ($this->limit === null || $media->getType() !== $media::IMAGE) {
            return $media;
        }

        // resize if image > limit
        if ($media->getWidth() > $this->limit || $media->getHeight() > $this->limit) {
            $resize = new Resize($this, $media);
            $resize->setTargetSize($this->limit, $this->limit);
            $resize->apply();
        }

        return $media;
    }