Public URL doesn't work

#1

Hi all,

I have a problem with Public URL of assets. I followed this: https://pimcore.com/docs/5.x/Development_Documentation/Installation_and_Upgrade/System_Setup_and_Hosting/Amazon_AWS_Setup/Amazon_AWS_S3_Setup.html to set s3 server with pimcore and it is working very well but now I have another problem with Public URL. It always returns 404 error

Please help me to solve this issue.
Thanks in advance

#2

I think the problem is with .htaccess file

#3

I just ran into this as well, after following the installation and S3 guide. Do your public urls look like the traditional non-S3 ones?

I think the url itself is incorrect, Public Url should be a S3 url, matching the frontend urls which do seem to be working correctly.

I’m super new to Pimcore. Please provide your solution if you found one.

Edit: here’s a little hack to make Public Url an S3 url, for AssetController.php. I have no clue if this is a proper implementation. I don’t think it affects API returned data either.

// S3 Support
// Cannot use getFullPath() here because it does not fire the frontend S3 event since
// this is NOT a frontend request! However, PIMCORE_TRANSFORMED_ASSET_URL seems to be
// implemented for this purpose, "constants for reference in the views".
$data['url'] = Tool::getHostUrl(null, $request) . $asset->getRealFullPath();
if (defined('PIMCORE_TRANSFORMED_ASSET_URL')) {
    $data['url'] = PIMCORE_TRANSFORMED_ASSET_URL . $asset->getRealFullPath();
}
#4

I have my own hack too. If you follow https://pimcore.com/docs/5.x/Development_Documentation/Installation_and_Upgrade/System_Setup_and_Hosting/Amazon_AWS_Setup/Amazon_AWS_S3_Setup.html you can change the /app/config/services.yml to this:

    services:
        _defaults:
            autowire: true
            autoconfigure: true
            public: false

        CommonBundle\EventListener\S3Listener:
            tags:
                - { name: kernel.event_listener, event: pimcore.frontend.path.asset.image.thumbnail, method: onFrontendPathThumbnail }
                - { name: kernel.event_listener, event: pimcore.frontend.path.asset.document.image-thumbnail, method: onFrontendPathThumbnail }
                - { name: kernel.event_listener, event: pimcore.frontend.path.asset.video.image-thumbnail, method: onFrontendPathThumbnail }
                - { name: kernel.event_listener, event: pimcore.frontend.path.asset.video.thumbnail, method: onFrontendPathThumbnail }
                - { name: kernel.event_listener, event: pimcore.asset.image.thumbnail, method: onAssetThumbnailCreated }
                - { name: kernel.event_listener, event: pimcore.asset.video.image-thumbnail, method: onAssetThumbnailCreated }
                - { name: kernel.event_listener, event: pimcore.asset.document.image-thumbnail, method: onAssetThumbnailCreated }
                - { name: kernel.event_listener, event: pimcore.frontend.path.asset, method: onFrontEndPathAsset }
                - { name: kernel.event_listener, event: kernel.request, method: onPublicURLRequested }

Then add this method into S3Listener.php file:

    public function onPublicURLRequested($event) {
        $request = Request::createFromGlobals();
        $uri = $request->getPathInfo();
        if (file_exists(PIMCORE_ASSET_DIRECTORY . $uri)) {
            $imginfo = getimagesize( PIMCORE_ASSET_DIRECTORY . $uri );
            header("Content-type: ".$imginfo['mime']);
            readfile(PIMCORE_ASSET_DIRECTORY . $uri);
            die();
        }
    }
#5

@raxcido Thanks for the response! I like your custom event handler.

1 Like