public function import($pointer, $filename = false, $fr = false, $prefix = null)
    {
        $fh = $this->app->make('helper/validation/file');
        $fi = $this->app->make('helper/file');
        $cf = $this->app->make('helper/concrete/file');

        $filename = (string) $filename;
        if ($filename === '') {
            // determine filename from $pointer
            $filename = basename($pointer);
        }

        $sanitizedFilename = $fi->sanitize($filename);

        // test if file is valid, else return FileImporter::E_FILE_INVALID
        if (!$fh->file($pointer)) {
            return self::E_FILE_INVALID;
        }

        if (!$fh->extension($filename)) {
            return self::E_FILE_INVALID_EXTENSION;
        }

        if ($fr instanceof FileEntity) {
            $fsl = $fr->getFileStorageLocationObject();
        } else {
            $fsl = $this->app->make(StorageLocationFactory::class)->fetchDefault();
        }
        if (!($fsl instanceof StorageLocation)) {
            return self::E_FILE_INVALID_STORAGE_LOCATION;
        }

        // store the file in the file storage location.
        $filesystem = $fsl->getFileSystemObject();
        if ($prefix) {
            $prefixIsAutoGenerated = false;
        } else {
            // note, if you pass in a prefix manually, make sure it conforms to standards
            // (e.g. it is 12 digits, numeric only)
            $prefix = $this->generatePrefix();
            $prefixIsAutoGenerated = true;
        }

        $src = @fopen($pointer, 'rb');
        if ($src === false) {
            return self::E_FILE_INVALID;
        }
        try {
            $filesystem->writeStream(
                $cf->prefix($prefix, $sanitizedFilename),
                $src,
                [
                    'visibility' => AdapterInterface::VISIBILITY_PUBLIC,
                    'mimetype' => $this->app->make('helper/mime')->mimeFromExtension($fi->getExtension($sanitizedFilename)),
                ]
            );
        } catch (Exception $e) {
            if (!$prefixIsAutoGenerated) {
                return self::E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED;
            } else {
                return self::E_FILE_UNABLE_TO_STORE;
            }
        } finally {
            @fclose($src);
        }

        if (!($fr instanceof FileEntity)) {
            // we have to create a new file object for this file version
            $fv = File::add($sanitizedFilename, $prefix, ['fvTitle' => $filename], $fsl, $fr);
        } else {
            // We get a new version to modify
            $fv = $fr->getVersionToModify(true);
            $fv->updateFile($sanitizedFilename, $prefix);
        }

        $fv->refreshAttributes(false);
        foreach ($this->importProcessors as $processor) {
            if ($processor->shouldProcess($fv)) {
                $processor->process($fv);
            }
        }
        if ($this->rescanThumbnailsOnImport) {
            $fv->refreshThumbnails(true);
        }
        $fv->releaseImagineImage();

        return $fv;
    }