php - Gaufrette and Symfony 2: There is no filesystem defined for the "images" domain -
i'm using symfony3 knpgaufrettebundle connect amazon s3 bucket aws s3 method outlined on github readme
aws_s3_adapter: key: "%aws_key%" secret_key: "%aws_secret%" region: "%aws_region%" knp_gaufrette: adapters: images: aws_s3: service_id: 'aws_s3_adapter.client' bucket_name: '%aws_bucket%' options: directory: 'images' filesystems: images: adapter: images alias: images_fs
i have service defined want use manage filesystem (and others) with.
definition:
services: test.image_manager: class: testbundle\filesystem\filemanager arguments: filesystem: "@images_fs" filesystem_name: "images" mimetypes: ["image/jpeg", "image/png", "image/gif"]
class:
<?php namespace testbundle\filesystem; use symfony\component\httpfoundation\file\uploadedfile; use symfony\component\httpfoundation\binaryfileresponse; use gaufrette\filesystem; use gaufrette\streamwrapper; class filemanager { private $allowedmimetypes; private $filesystem; private $filsystem_name; public function __construct(filesystem $filesystem, $filesystem_name, $mimetypes = array()) { $this->filesystem = $filesystem; $this->filesystem_name = $filesystem_name; $this->allowedmimetypes = $mimetypes; } public function upload(uploadedfile $file, $filename) { // check if file's mime type in list of allowed mime types. if (!in_array($file->getclientmimetype(), $this->allowedmimetypes)) { throw new \invalidargumentexception(sprintf('files of type %s not allowed.', $file->getclientmimetype())); } $adapter = $this->filesystem->getadapter(); $adapter->setmetadata($filename, array('contenttype' => $file->getclientmimetype())); return $adapter->write($filename, file_get_contents($file->getpathname())); } public function fetch( $filename ) { if( ! $this->filesystem->has( $filename ) ) { return false; } /* -- problem -- */ streamwrapper::register(); return new binaryfileresponse( "gaufrette://{$this->filesystem_name}/{$filename}" ); /* -- problem -- */ } public function delete( $filename ) { if( ! $this->filesystem->has( $filename ) ) { return false; } return $this->filesystem->delete( $filename ); } }
i'm able upload bucket using upload function, telling me filesystem exists , working properly.
i not, however, able use gaufrette\streamwrapper serve file using binaryfileresponse says should do. instead giving me error put in title: there no filesystem defined "images" domain.
the filesystem exists, i'm using upload images. clues problem might that's preventing me using filesystem helpful. gaufrette documentation sparse online far i've found, i'm going keep digging.
looking @ mainconfiguration.php showed there's steam_wrapper
option in configuration bundle. added config.yml
under filesystems defined so:
knp_gaufrette: adapters: images: aws_s3: service_id: 'aws_s3_adapter.client' bucket_name: '%aws_bucket%' options: directory: 'images' . . . filesystems: images: adapter: images alias: images_fs . . . stream_wrapper: filesystems: [ images, ... ]
and above code works.