Flysystem is a filesystem abstraction library for PHP. It provides an abstraction for the filesystem in order to change the storage backend depending on the execution environment (local files in development, cloud storage in production and memory in tests) and your configuration.
Read the official library documentation
VichUploaderBundle can use Flysystem as a storage engine by relying on one of two bundles: thephpleague/flysystem-bundle or oneup/flysystem-bundle.
Note:
When using
flysystem
as the storage engine, you can still use the same mappings options that you would use with default storage.
Integrating with thephpleague/flysystem-bundle
To install the bundle, run the following command:
composer require league/flysystem-bundle
It will create a default YAML configuration using Symfony Flex:
# config/packages/flysystem.yaml
flysystem:
storages:
default.storage:
adapter: 'local'
options:
directory: '%kernel.project_dir%/var/storage/default'
You can adapt this configuration to your needs by reading the bundle documentation.
Once you have a storage ready, you can use it in your VichUploaderBundle configuration:
vich_uploader:
db_driver: orm
storage: flysystem
mappings:
products:
uri_prefix: /images/products
upload_destination: default.storage # Use the name you defined for your storage here
If you are using certain adapters like S3, Cloudflare, etc., the generated public URL for assets may be incorrect.
To resolve this, you can enable use_flysystem_to_resolve_uri
in the configuration.
This setting makes VichUploaderBundle retrieve the public URL from the configured Flysystem storage. If Flysystem cannot generate a public URL, the bundle will fall back to default behaviour.
Note::
Retrieving the public URL is only available when using flysystem version 3.6.0 and up.
Integrating with oneup/flysystem-bundle
To install the bundle, run the following command:
composer require oneup/flysystem-bundle
Here is a sample configuration that stores your file in your local filesystem, but you can use your preferred adapters and FS (for details on this topic you should refer to the bundle documentation).
oneup_flysystem:
adapters:
product_adapter:
local:
location: '%kernel.project_dir%/public/images/products'
filesystems:
products:
adapter: product_adapter
mount: products
vich_uploader:
db_driver: orm
storage: flysystem
mappings:
products:
uri_prefix: /images/products
# For Oneup/FlysystemBundle v4
upload_destination: oneup_flysystem.products_filesystem
# For Oneup/FlysystemBundle v3
# upload_destination: products
Check out the docs for information on how to use the bundle! Return to the index.