liip_imagine with vich_uploader not creating cache

江枫思渺然 提交于 2019-12-05 21:31:54

In getMediaItemFile, add the liip_imagine.data.manager, and liip_imagine.filter.manager as dependencies, too, and try:

if (!$this-> liipImagineCacheManager->isStored($filePath, $size)) {
    $binary = $this->dataManager->find($size, $filePath);

    $filteredBinary = $this->filterManager->applyFilter($binary, $size);

    // This should store the thumbnail in web/images/media/cache
    $this->liipImagineCacheManager->store($filteredBinary, $filePath, $filterName);
}

// or similar
return $this->liipImagineCacheManager->resolve($filePath, $filterName);

This just lets you be more explicit about storing to the liip cache folders, e.g. in your web/images folder.

(Small, unrelated point - you may consider breaking out that getMediaItemFile into a service that you call to resolve images. It's a bit out of place in an entity model class.)

For everyone who comes here i could finally find the problem. The problem is separated into two main problems first the liip_imagine config file should be as follows:

liib_imagine.yml

# LiipImagineBundle
liip_imagine:
    resolvers:
        default:
            web_path:
                web_root: %kernel.root_dir%/../../web/images
                cache_prefix: media/cache
    loaders:
        default:
            filesystem:
                data_root: %kernel.root_dir%/../../web/images
    filter_sets:
        image_xlarge:
            filters:
                thumbnail: { size: [1080, 708], mode: outbound }
        image_large:
            filters:
                thumbnail: { size: [535, 351], mode: outbound }
        thumb_large:
            filters:
                thumbnail: { size: [400, 262], mode: outbound }
        thumb_medium:
            filters:
                thumbnail: { size: [264, 173], mode: outbound }
        thumb_small:
            filters:
                thumbnail: { size: [250, 164], mode: outbound }
        thumb_xsmall:
            filters:
                thumbnail: { size: [175, 115], mode: outbound }
        square_large:
            filters:
                thumbnail: { size: [500, 500], mode: outbound }
        square_medium:
            filters:
                thumbnail: { size: [250, 250], mode: outbound }
        square_small:
            filters:
                thumbnail: { size: [100, 100], mode: outbound }
        square_xsmall:
            filters:
                thumbnail: { size: [50, 50], mode: outbound }

notice the data_root in the loaders > file system. second is the "../" issue with this bundle for some reason the function getMediaItemAction didn't accept that i add "../../" to it so i had to get rid of it and the problem were solved and now the cache is working.

getMediaIteamAction function

/**
     * Get path for media item file
     *
     * @param MediaItem $mediaItem
     * @param $size
     * @return string
     */
    public function getMediaItemFile(MediaItem $mediaItem, $size)
    {
       $fileName = '/media/library/' . $mediaItem->getName();
        if ($mediaItem->getServiceProvider()) {
            $fileName = '/media/serviceprovider/' . $mediaItem->getId() . '/' . $mediaItem->getName();
        }

        $this->liipImagineController
            ->filterAction(new Request(), $fileName, $size);

        $this->liipImagineCacheManager->getBrowserPath($fileName, $size);

        $result = '/media/cache/' . $size . '/media/library/' . $mediaItem->getName();

        if ($mediaItem->getServiceProvider()) {
            $result = '/media/cache/' . $size . '/media/serviceprovider/' . $mediaItem->getId() . '/' . $mediaItem->getName();
        }

        return $result;
    }

notice that the "../../" is now removed

also regarding to @Camerogn Hurd the another answer to this question the function he mentioned might fix some issues because its totally working also to force create the cache but you also need to get rid of "../" since the bundle doesn't accept this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!