LiipImageBundle & KNP Gaufrette bundle failing to resolve s3 image path?

954 views Asked by At

I am using LiipImageBundle & KNP Gaufrette bundle to resize & load images from s3. It was all working before but suddenly it stopped working. There are no bundle version upgrades.

Below is my configuration,

liip_imagine:
    cache: aws_s3_images
    data_loader: stream.aws_s3_images
    filter_sets:
        large:
            quality: 75
            cache: aws_s3_images
            data_loader: stream.aws_s3_images
            filters:
                relative_resize: { widen: 140 }
        medium:
            quality: 75
            cache: aws_s3_images
            data_loader: stream.aws_s3_images
            filters:
                thumbnail: { size: [50, 50], mode: outbound }
        small:
            quality: 75
            cache: aws_s3_images
            data_loader: stream.aws_s3_images
            filters:
                thumbnail: { size: [25, 25], mode: outbound }

    loaders:
        stream.aws_s3_images:
            stream:
                wrapper: gaufrette://aws_s3_images_fs/

knp_gaufrette:
    adapters:
        aws_s3_images_adapter:
            aws_s3:
                service_id: 'st.aws_s3.client'
                bucket_name: %amazon.s3.bucket%
                options:
                    #directory: 'fos'
                    create: true

    filesystems:
        aws_s3_images_fs:
            adapter:    aws_s3_images_adapter

    stream_wrapper: ~

The problem is strange, if I open image in new tab, it redirects to s3 image url and displays image. Once it loads in new tab, then it starts displaying normally. It doesnt work unless I open it new new tab.

is it not resolving s3 path ? What could be the issue ? I tried deleting all cache, I don't have media folder in my web directory.

In log it shows ImagineController:FilterAction is called.

In html source image path is

http://st.com/app_dev.php/media/cache/resolve/large/fos/user/ebc36103e6d1038791eb7eca2f4449db0780fdf41416235134.jpeg

Now if I open it in new tab/window, it will redirect to

[MY_S3_BUCKET_URL]/fos/user/large/ebc36103e6d1038791eb7eca2f4449db0780fdf41416235134.jpeg

and will display image in new window.

Now if I again refresh my page, image source is now changed to

[MY_S3_BUCKET_URL]/fos/user/large/ebc36103e6d1038791eb7eca2f4449db0780fdf41416235134.jpeg

and now I can see image loaded ?

Why it started happening suddenly. It was all working properly before.

1

There are 1 answers

0
vishal On BEST ANSWER

After going through all the code of LiipImaginBundle & debugging, it turned out to be content type issue which was caused by FOSRestBundle's

format_listener:
    rules:
        - { path: '^/', priorities: [ '*/*' ], fallback_format: html, prefer_extension: true }

Changing it to

format_listener:
    rules:
        - { path: '^/', priorities: [ 'html', '*/*' ], fallback_format: html, prefer_extension: true }

fixed the issue.