Instead of use the Symfony filesystem as storage layer you can use the Gaufrette solution that is a more robust option and provides different adapters, for example, it can store in an easy way the data in S3.
Firstly, install the bundle with Composer
$ composer require bengor-file/gaufrette-filesystem-bridge-bundleOnce the bundle has been installed enable it in the AppKernel:
// app/config/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
new BenGorFile\GaufretteFilesystemBridgeBundle\BenGorFileGaufretteFilesystemBridgeBundle(),
// ...
];
}In order to use Gaufrette you have to configure it. Here is a sample configuration that stores your file in your local filesystem, but keep in mind, you can use your preferred adapters. Check the Gaufrette documentation for more information.
# app/config/config.yml
knp_gaufrette:
stream_wrapper: ~
adapters:
image_adapter:
local:
directory: '%kernel.root_dir%/../web/uploads/images'
create: true
filesystems:
image_filesystem:
adapter: image_adapter
ben_gor_file:
file_class:
image:
class: AppBundle\Entity\Image
storage: gaufrette
upload_destination: image_filesystemNote:
Make sure that Gaufrette stream wrapper is enabled and its protocol must have the
gaufrettename, otherwise it does not work.
Note:
In this case
upload_destinationrefers to a Gaufrette filesystem.
- Back to the index.