Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using (fully) KnpGaufrette to provide an abstraction for files uploading/reading #344

Open
Kocal opened this issue Jan 20, 2021 · 1 comment

Comments

@Kocal
Copy link

Kocal commented Jan 20, 2021

Hi, 👋
First, let me thank you for the plugin. We are planning to use Sylius for creating new ecommerce websites for our customers, and the "CMS feature" was definitely missing from Sylius.. so thanks! :)

We are still in the testing phase and we faced an issue with the plugin and the way used for uploading/reading files.

For some context, I configured Sylius to upload files to a S3 bucket (Scaleway) by using this configuration:

# config/packages/knp_gaufrette.yaml

knp_gaufrette:
    adapters:
        sylius_image:
            aws_s3:
                service_id: Aws\S3\S3Client
                bucket_name: '%aws.s3.bucket%'
                detect_content_type: true
                options:
                    directory: '%env(AWS_S3_PREFIX)%/media/image'
                    acl: 'public-read'
    stream_wrapper: ~

# config/packages/liip_imagine.yaml
liip_imagine:
    loaders:
        aws_s3:
            stream:
                wrapper: gaufrette://sylius_image/
    resolvers:
        aws_s3:
            aws_s3:
                # By doing this, we won't let LiipImagineBundle create another S3Client instance instead of re-using the existing one.
                # The service "liip_imagine.cache.resolver.aws_s3.client" must be defined manually.
                client_config: ~ 
                bucket: '%aws.s3.bucket%'
                get_options:
                    Scheme: https
                put_options:
                    CacheControl: 'max-age=86400'
                cache_prefix: '%env(AWS_S3_PREFIX)%/media/cache'
    data_loader: aws_s3
    cache: aws_s3

and it works fine (e.g.: uploading a photo for a product).

However, this does not work with the plugin. When you upload an image through CKEditor (provided by the plugin), the file will be saved the disk where the project lives (e.g.: /.../public/media/...).

I've read the code and trying to understand how to change that, and I found a parameter bitbag_sylius_cms_plugin.uploader.filesystem.
I changed its value to my Gaufrette adapter sylius_image, this way the service bitbag_sylius_cms_plugin.media.filesystem (used by service bitbag_sylius_cms_plugin.media_uploader, then used by service bitbag_sylius_cms_plugin.media_provider.image) will upload images to S3, but this does not work:
image
image
image

But the file is not uploaded anymore (not on the filesystem nor on S3), and the upload action returns a media path that does not exists:
image

Before investigating more, I've also found that \BitBag\SyliusCmsPlugin\Controller\PageController::resolveImage is using the filesystem to get the file, not Gaufrette's Flysystem, making it unusable when medias should can't be stored in the public directory:
image

Do you know if fully Gaufrette support is planned, and if we can easily implement it?

Thanks!

@laurentdabbb
Copy link

Hi,

Up !
Please provide a fully support for external filesystem.

Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants