thephpleague / glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.
http://glide.thephpleague.com
MIT License
2.54k stars 198 forks source link

locale srouce and cache with cdn setting #391

Open langziyang opened 4 months ago

langziyang commented 4 months ago

source file and cache is on locale. but i have setting amazon CloudFront.

when direct request 'https://xxxx.cloudfront.net/product/1/Soft-Axami_1_6607c41abda77.jpg' it work.

but i want use glide so i created router like this:

#[Route('/image/read', name: 'image.read')]
    public function readImage(Request $request, ConfigurationService $configurationService)
    {
        try {
            $domain=$configurationService->getSetting('SYSTEM_IMAGE_DOMAIN',true);
            if(!$domain){
                $request->getSchemeAndHttpHost();
            }
            $path = $request->query->get('path');

            $source_dir = $this->getParameter('kernel.project_dir') . '/public';
            $server = ServerFactory::create([
                'source' => new Filesystem(new LocalFilesystemAdapter($source_dir)),
                'response' => new SymfonyResponseFactory(),
                'cache' => $source_dir . '/cache',
                'driver' => 'imagick',
            ]);
            $query = $request->query->all();
            unset($query['path']);
            return $server->getImageResponse($path, $query);
        } catch (\Exception $e) {
            return new RedirectResponse('');
        }
    }

i want kown how can i use amazon CloudFront return cache file