public function uploadFile($filename)
    {

        // trim the leading /, if available
        $trimmedFilename = ltrim($filename, '/');
        $mediaDir = ltrim($this->getMediaDir(), '/');
        $imagesFileDir = ltrim($this->getImagesFileDir(), '/');

        // prepare source/target filename
        $sourceFilename = sprintf('%s/%s', $imagesFileDir, $trimmedFilename);
        $targetFilename = sprintf('%s/%s', $mediaDir, $trimmedFilename);

        // query whether or not the image file to be imported is available
        if (!$this->getFilesystemAdapter()->isFile($sourceFilename)) {
            throw new \Exception(sprintf('Media file %s not available', $sourceFilename));
        }

        // prepare the target filename, if necessary
        $newTargetFilename = $this->getNewFileName($targetFilename);
        $targetFilename = str_replace(basename($targetFilename), $newTargetFilename, $targetFilename);

        // make sure, the target directory exists
        if (!$this->getFilesystemAdapter()->isDir($targetDirectory = dirname($targetFilename))) {
            $this->getFilesystemAdapter()->mkdir($targetDirectory, 0755);
        }

        // copy the image to the target directory
        $this->getFilesystemAdapter()->copy($sourceFilename, $targetFilename);

        // return the new target filename
        return str_replace($mediaDir, '', $targetFilename);
    }