commit_id
string
repo
string
commit_message
string
diff
string
label
int64
d30b3a48547daac095759a2cb5f4acb832e5e568
1up-lab/OneupUploaderBundle
Merge pull request #181 from 1up-lab/sheeep-patch-1 Changed $file to $chunk.
commit d30b3a48547daac095759a2cb5f4acb832e5e568 (from 1fe30e7afcb0cd9965701c34f61902011a895aec) Merge: 1fe30e7 2453924 Author: Jim Schmid <[email protected]> Date: Mon Jun 15 17:41:49 2015 +0200 Merge pull request #181 from 1up-lab/sheeep-patch-1 Changed $file to $chunk. diff --git a/Event/PostChunkUploadEvent.php b/Event/PostChunkUploadEvent.php index 9b32dfd..32e8fe7 100644 --- a/Event/PostChunkUploadEvent.php +++ b/Event/PostChunkUploadEvent.php @@ -8,7 +8,7 @@ use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; class PostChunkUploadEvent extends Event { - protected $file; + protected $chunk; protected $request; protected $type; protected $response;
0
6f5dd7455246980d422541e301ddaba11376becf
1up-lab/OneupUploaderBundle
Added missing newline.
commit 6f5dd7455246980d422541e301ddaba11376becf Author: Jim Schmid <[email protected]> Date: Sun Jun 23 13:51:18 2013 +0200 Added missing newline. diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 07c869d..7caffb4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,4 +21,4 @@ </exclude> </whitelist> </filter> -</phpunit> \ No newline at end of file +</phpunit>
0
2ddf07a2796b99e82fb0d29ed69425d752f4e392
1up-lab/OneupUploaderBundle
Removed HandlerInterface, not very flexible, after all.
commit 2ddf07a2796b99e82fb0d29ed69425d752f4e392 Author: Jim Schmid <[email protected]> Date: Tue Mar 12 16:25:56 2013 +0100 Removed HandlerInterface, not very flexible, after all. diff --git a/Uploader/Handler/HandlerInterface.php b/Uploader/Handler/HandlerInterface.php deleted file mode 100644 index ec7cb5f..0000000 --- a/Uploader/Handler/HandlerInterface.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php - -namespace Oneup\UploaderBundle\Uploader\Handler; - -interface HandlerInterface -{ - public function perform(); -} \ No newline at end of file
0
f5acda92ea3d6aa482408d1ef65a69f46efb3802
1up-lab/OneupUploaderBundle
Y u no automatic linking Github?
commit f5acda92ea3d6aa482408d1ef65a69f46efb3802 Author: David Greminger <[email protected]> Date: Thu Jan 28 16:06:49 2016 +0100 Y u no automatic linking Github? diff --git a/README.md b/README.md index 3384dae..d0f6ed6 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- -* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR #213) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). +* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). * Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57). * If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320). * Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md).
0
5da645b523edb24f79a0b9360b43bfa196c3276d
1up-lab/OneupUploaderBundle
First version of Plupload implementation.
commit 5da645b523edb24f79a0b9360b43bfa196c3276d Author: Jim Schmid <[email protected]> Date: Fri Apr 12 15:40:28 2013 +0200 First version of Plupload implementation. diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php new file mode 100644 index 0000000..ede7a8d --- /dev/null +++ b/Controller/PluploadController.php @@ -0,0 +1,43 @@ +<?php + +namespace Oneup\UploaderBundle\Controller; + +use Symfony\Component\HttpFoundation\File\Exception\UploadException; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; + +use Oneup\UploaderBundle\Controller\AbstractChunkedController; +use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; + +class PluploadController extends AbstractChunkedController +{ + public function upload() + { + $request = $this->container->get('request'); + $response = new EmptyResponse(); + $files = $request->files; + + foreach($files as $file) + { + try + { + $uploaded = $this->handleUpload($file); + + // dispatch POST_PERSIST AND POST_UPLOAD events + $this->dispatchEvents($uploaded, $response, $request); + } + catch(UploadException $e) + { + // return nothing + return new JsonResponse(array()); + } + } + + return new JsonResponse($response->assemble()); + } + + protected function parseChunkedRequest(Request $request) + { + die("foobar"); + } +} \ No newline at end of file diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b00f847..e33d623 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -35,7 +35,7 @@ class Configuration implements ConfigurationInterface ->prototype('array') ->children() ->enumNode('frontend') - ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload')) + ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload')) ->defaultValue('fineuploader') ->end() ->arrayNode('storage') diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 8b1cc48..49de680 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -17,6 +17,7 @@ <parameter key="oneup_uploader.controller.yui3.class">Oneup\UploaderBundle\Controller\YUI3Controller</parameter> <parameter key="oneup_uploader.controller.fancyupload.class">Oneup\UploaderBundle\Controller\FancyUploadController</parameter> <parameter key="oneup_uploader.controller.mooupload.class">Oneup\UploaderBundle\Controller\MooUploadController</parameter> + <parameter key="oneup_uploader.controller.plupload.class">Oneup\UploaderBundle\Controller\PluploadController</parameter> </parameters> <services>
0
66de7cc175a134c8009f1cd9612e0b22ee8cce12
1up-lab/OneupUploaderBundle
The parameter is now required for Storage::upload()
commit 66de7cc175a134c8009f1cd9612e0b22ee8cce12 Author: Jim Schmid <[email protected]> Date: Sat Apr 6 20:12:55 2013 +0200 The parameter is now required for Storage::upload() diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php index f756476..fcc3e51 100644 --- a/Uploader/Storage/FilesystemStorage.php +++ b/Uploader/Storage/FilesystemStorage.php @@ -16,7 +16,7 @@ class FilesystemStorage implements StorageInterface $this->directory = $directory; } - public function upload(File $file, $name = null, $path = null) + public function upload(File $file, $name, $path = null) { $filesystem = new Filesystem(); diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index 7f3978e..fac7bbe 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -18,7 +18,7 @@ class GaufretteStorage implements StorageInterface $this->filesystem = $filesystem; } - public function upload(File $file, $name = null, $path = null) + public function upload(File $file, $name, $path = null) { $name = is_null($name) ? $file->getRelativePathname() : $name; $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name); diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php index f048df2..6477358 100644 --- a/Uploader/Storage/OrphanageStorage.php +++ b/Uploader/Storage/OrphanageStorage.php @@ -28,7 +28,7 @@ class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInte $this->type = $type; } - public function upload(File $file, $name = null, $path = null) + public function upload(File $file, $name, $path = null) { if(!$this->session->isStarted()) throw new \RuntimeException('You need a running session in order to run the Orphanage.'); diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php index 3684604..e4e3dce 100644 --- a/Uploader/Storage/StorageInterface.php +++ b/Uploader/Storage/StorageInterface.php @@ -6,5 +6,5 @@ use Symfony\Component\HttpFoundation\File\File; interface StorageInterface { - public function upload(File $file, $name = null, $path = null); + public function upload(File $file, $name, $path = null); } \ No newline at end of file
0
f61d2d1a0ea6ce33d9582d80f7489bb81f4cf38c
1up-lab/OneupUploaderBundle
Fixed path madness introduced due to reimplementation of Orphanage.
commit f61d2d1a0ea6ce33d9582d80f7489bb81f4cf38c Author: Jim Schmid <[email protected]> Date: Thu Mar 28 16:11:36 2013 +0100 Fixed path madness introduced due to reimplementation of Orphanage. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index 465b264..a0072cc 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -115,7 +115,7 @@ class UploaderController implements UploadControllerInterface // validate this entity and upload on success $this->validate($uploadedFile); - $uploaded = $this->handleUpload(); + $uploaded = $this->handleUpload($uploadedFile); $this->chunkManager->cleanup($path); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9987fb7..a19fb50 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -28,6 +28,7 @@ class Configuration implements ConfigurationInterface ->booleanNode('enabled')->defaultFalse()->end() ->scalarNode('filesystem')->defaultNull()->end() ->scalarNode('maxage')->defaultValue(604800)->end() + ->scalarNode('directory')->defaultValue('orphanage')->end() ->end() ->end() ->arrayNode('mappings') diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 1ca00ec..b1768df 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -27,15 +27,7 @@ class OneupUploaderExtension extends Extension } $container->setParameter('oneup_uploader.chunks', $config['chunks']); - - // handling orphanage configuration - if(!array_key_exists('directory', $config['orphanage'])) - { - $config['orphanage']['directory'] = sprintf('%s/uploader/orphanage', $container->getParameter('kernel.cache_dir')); - } - $container->setParameter('oneup_uploader.orphanage', $config['orphanage']); - //$config['orphanage']['storage'] = $this->registerStorageService($container, $config['orphanage']); // handle mappings foreach($config['mappings'] as $key => $mapping) diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index 66b074f..7f3978e 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -18,19 +18,19 @@ class GaufretteStorage implements StorageInterface $this->filesystem = $filesystem; } - public function upload(File $file, $name = null) + public function upload(File $file, $name = null, $path = null) { - $path = $file->getPathname(); $name = is_null($name) ? $file->getRelativePathname() : $name; + $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name); - $src = new LocalStream($path); - $dst = $this->filesystem->createStream($name); + $src = new LocalStream($file->getPathname()); + $dst = $this->filesystem->createStream($path); // this is a somehow ugly workaround introduced // because the stream-mode is not able to create // subdirectories. - if(!$this->filesystem->has($name)) - $this->filesystem->write($name, '', true); + if(!$this->filesystem->has($path)) + $this->filesystem->write($path, '', true); $src->open(new StreamMode('rb+')); $dst->open(new StreamMode('ab+')); @@ -44,6 +44,6 @@ class GaufretteStorage implements StorageInterface $dst->close(); $src->close(); - return $this->filesystem->get($name); + return $this->filesystem->get($path); } } \ No newline at end of file diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php index 27f83ec..096af12 100644 --- a/Uploader/Storage/OrphanageStorage.php +++ b/Uploader/Storage/OrphanageStorage.php @@ -28,12 +28,15 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter $this->type = $type; } - public function upload(File $file, $name = null) + public function upload(File $file, $name = null, $path = null) { if(!$this->session->isStarted()) throw new \RuntimeException('You need a running session in order to run the Orphanage.'); - return parent::upload($file, $name); + // generate a path based on session id + $path = $this->getPath(); + + return parent::upload($file, $name, $path); } public function uploadFiles($keep = false) @@ -47,7 +50,7 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter if(!$system->exists($this->getPath())) return array(); - $finder->in($this->getPathRelativeToSession())->files(); + $finder->in($this->getPath())->files(); $uploaded = array(); foreach($finder as $file) @@ -64,14 +67,6 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter } protected function getPath() - { - $id = $this->session->getId(); - $path = sprintf('%s/%s/%s', $this->config['directory'], $id, $this->type); - - return $path; - } - - protected function getPathRelativeToSession() { $id = $this->session->getId(); $path = sprintf('%s/%s', $this->config['directory'], $id); diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php index 74a63df..3684604 100644 --- a/Uploader/Storage/StorageInterface.php +++ b/Uploader/Storage/StorageInterface.php @@ -6,5 +6,5 @@ use Symfony\Component\HttpFoundation\File\File; interface StorageInterface { - public function upload(File $file, $name); + public function upload(File $file, $name = null, $path = null); } \ No newline at end of file
0
85d82bb2f2d9d917afb2d3560b4849cda01ca2b2
1up-lab/OneupUploaderBundle
Made all the validators non-public.
commit 85d82bb2f2d9d917afb2d3560b4849cda01ca2b2 Author: Jim Schmid <[email protected]> Date: Mon Apr 22 19:39:25 2013 +0200 Made all the validators non-public. diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml index 3daeb90..c87a978 100644 --- a/Resources/config/validation.xml +++ b/Resources/config/validation.xml @@ -9,6 +9,7 @@ <service id="oneup_uploader.validation_listener.max_size" class="Oneup\UploaderBundle\EventListener\MaxSizeValidationListener" + public="false" > <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> </service> @@ -16,6 +17,7 @@ <service id="oneup_uploader.validation_listener.allowed_extension" class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener" + public="false" > <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> </service> @@ -23,6 +25,7 @@ <service id="oneup_uploader.validation_listener.disallowed_extension" class="Oneup\UploaderBundle\EventListener\DisallowedExtensionValidationListener" + public="false" > <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> </service>
0
2db6ca7525c44395e2208f5ad31908876091bee3
1up-lab/OneupUploaderBundle
Reimplemented original addToOffset method.
commit 2db6ca7525c44395e2208f5ad31908876091bee3 Author: Jim Schmid <[email protected]> Date: Mon Jul 15 08:55:26 2013 +0200 Reimplemented original addToOffset method. diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php index 69836c3..299dae1 100644 --- a/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -16,6 +16,6 @@ class BlueimpErrorHandler implements ErrorHandlerInterface $message = $exception->getMessage(); } - $response->addToOffset('files', array('error' => $message)); + $response->addToOffset(array('error' => $message), 'files'); } } diff --git a/Uploader/Response/AbstractResponse.php b/Uploader/Response/AbstractResponse.php index 913b000..3745f62 100644 --- a/Uploader/Response/AbstractResponse.php +++ b/Uploader/Response/AbstractResponse.php @@ -33,12 +33,34 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface return isset($this->data[$offset]) ? $this->data[$offset] : null; } - public function addToOffset($offset, array $value) + /** + * The \ArrayAccess interface does not support multi-dimensional array syntax such as $array["foo"][] = bar + * This function will take a path of arrays and add a new element to it, creating the path if needed. + * + * @param mixed $value + * @param mixed $offset,... + * + * @throws \InvalidArgumentException if the path contains non-array or unset items. + */ + public function addToOffset($value, $offset) { - if (!array_key_exists($offset, $this->data)) { - $this->data[$offset] = array(); - } + $args = func_get_args(); + array_shift($args); + + $element =& $this->data; - $this->data[$offset] += $value; + foreach ($args as $offset) { + if (isset($element[$offset])) { + if (is_array($element[$offset])) { + $element =& $element[$offset]; + } else { + throw new \InvalidArgumentException('The specified offset is set but is not an array at ' . $offset); + } + } else { + $element[$offset] = array(); + $element =& $element[$offset]; + } + } + $element[] = $value; } }
0
4967f7c84a6847a4802cb2b808f807bde95aae46
1up-lab/OneupUploaderBundle
Merge pull request #121 from Nyholm/patch-1 Added PHP 5.6 and HHVM to travis.yml
commit 4967f7c84a6847a4802cb2b808f807bde95aae46 (from 310ad454b8a23450f2a32b63a9c8f712daaa3934) Merge: 310ad45 ab23ea0 Author: Jim Schmid <[email protected]> Date: Fri Jul 18 15:07:04 2014 +0200 Merge pull request #121 from Nyholm/patch-1 Added PHP 5.6 and HHVM to travis.yml diff --git a/.travis.yml b/.travis.yml index bd24695..1d74818 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,27 @@ language: php php: - - 5.3 - - 5.4 - - 5.5 + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - hhvm env: - SYMFONY_VERSION=2.3.* - - SYMFONY_VERSION=2.4.* - - SYMFONY_VERSION=2.5.* + +matrix: + allow_failures: + - env: SYMFONY_VERSION=dev-master + - php: hhvm + include: + - php: 5.5 + env: SYMFONY_VERSION=2.4.* + - php: 5.5 + env: SYMFONY_VERSION=2.5.* + - php: 5.5 + env: SYMFONY_VERSION=dev-master before_script: - composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source - - composer install --dev --prefer-source \ No newline at end of file + - composer install --dev --prefer-source
0
ea3774346b722a84aa48e8181751b23b255f837c
1up-lab/OneupUploaderBundle
Changed description and tags in composer.json
commit ea3774346b722a84aa48e8181751b23b255f837c Author: Jim Schmid <[email protected]> Date: Fri Apr 12 12:33:36 2013 +0200 Changed description and tags in composer.json diff --git a/composer.json b/composer.json index d59371e..a8ae808 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "oneup/uploader-bundle", "type": "symfony-bundle", - "description": "widen/file-uploader integration", - "keywords": ["fileupload", "upload", "multifileupload", "chunked upload", "orphans"], + "description": "Handle multi file uploads. Features included: Chunked upload, Orphans management, Gaufrette support...", + "keywords": ["fileupload", "upload", "multifileupload", "chunked upload", "orphans", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload"], "homepage": "http://1up.io", "license": "MIT", "authors": [
0
8be7573e9178b30d27f947967b86ee029654aa68
1up-lab/OneupUploaderBundle
Merge pull request #217 from JHGitty/patch-3 #197 Update FineUploader doc to version 5
commit 8be7573e9178b30d27f947967b86ee029654aa68 (from 453e2f216418e48b93f70c0b40bcb9a66c488001) Merge: 453e2f2 d6a88f9 Author: Jim Schmid <[email protected]> Date: Mon Feb 8 08:33:00 2016 +0100 Merge pull request #217 from JHGitty/patch-3 #197 Update FineUploader doc to version 5 diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md index cd8a019..22fbb16 100644 --- a/Resources/doc/frontend_fineuploader.md +++ b/Resources/doc/frontend_fineuploader.md @@ -1,26 +1,27 @@ Use FineUploader ================ -Download [FineUploader](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. +Download [FineUploader 5](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. This example is based on the [UI Mode](http://docs.fineuploader.com/branch/master/quickstart/01-getting-started.html) of FineUploader. ```html -<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> -<script type="text/javascript" src="js/jquery.fineuploader-3.4.1.js"></script> +<link href="fine-uploader/fine-uploader-new.min.css" rel="stylesheet"> +<script type="text/javascript" src="fine-uploader/fine-uploader.min.js"></script> <script type="text/javascript"> -$(document).ready(function() -{ var uploader = new qq.FineUploader({ - element: $('#uploader')[0], + element: document.getElementById('fine-uploader'), request: { endpoint: "{{ oneup_uploader_endpoint('gallery') }}" } }); -}); </script> -<div id="uploader"></div> +<div id="fine-uploader"></div> ``` +You can find a fully example of all available settings on the [official documentation](http://docs.fineuploader.com/branch/master/quickstart/02-setting_options.html). + +If you are using Fine Uploader UI, as described in this example, you **MUST** include a template in your document/markup. You can use the ``default.html`` file in the templates directory bundled with the FineUploader library and customize it as desired. You even can use an inline template. See the official [styling documentation page](http://docs.fineuploader.com/branch/master/features/styling.html) for more details. + Configure the OneupUploaderBundle to use the correct controller: ```yaml commit 8be7573e9178b30d27f947967b86ee029654aa68 (from d6a88f980a1d49832e58cd876c8907f860d5e76a) Merge: 453e2f2 d6a88f9 Author: Jim Schmid <[email protected]> Date: Mon Feb 8 08:33:00 2016 +0100 Merge pull request #217 from JHGitty/patch-3 #197 Update FineUploader doc to version 5 diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index fd6d87a..c577309 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -1,7 +1,7 @@ Using Chunked Uploads ===================== -Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. +Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabled, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. ```js $(document).ready(function() diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md index c83002d..0d9dc17 100644 --- a/Resources/doc/custom_namer.md +++ b/Resources/doc/custom_namer.md @@ -24,7 +24,7 @@ class CatNamer implements NamerInterface } ``` -To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. +To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. The namer should return an unique name to avoid issues if the file already exists. Next, register your created namer as a service in your `services.xml` diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 4178e9e..39ab715 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -34,19 +34,9 @@ Perform the following steps to install and use the basic functionality of the On Add OneupUploaderBundle to your composer.json using the following construct: -```js -{ - "require": { - "oneup/uploader-bundle": "~1.4" - } -} -``` - -Now tell composer to download the bundle by running the following command: - - $> php composer.phar update oneup/uploader-bundle + $ composer require oneup/uploader-bundle "~1.4" -Composer will now fetch and install this bundle in the vendor directory ```vendor/oneup``` +Composer will install the bundle to your project's ``vendor/oneup/uploader-bundle`` directory. ### Step 2: Enable the bundle
0
988082eb6eda9f1f69182ed478a04f333c5766f5
1up-lab/OneupUploaderBundle
Extended documentation about chunked uploads and Gaufrette.
commit 988082eb6eda9f1f69182ed478a04f333c5766f5 Author: Jim Schmid <[email protected]> Date: Mon Oct 14 20:35:08 2013 +0200 Extended documentation about chunked uploads and Gaufrette. diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index 7eefd95..fd6d87a 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -37,10 +37,13 @@ oneup_uploader: You can choose a custom directory to save the chunks temporarily while uploading by changing the parameter `directory`. -Since version 1.0 you can also use a Gaufrette filesystem as the chunk storage. To do this you must first -set up [Gaufrette](gaufrette_storage.md). There are however some additional things to keep in mind. +## Use Gaufrette to store chunk files + +You can also use a Gaufrette filesystem as the chunk storage. A possible use case is to use chunked uploads behind non-session sticky load balancers. +To do this you must first set up [Gaufrette](gaufrette_storage.md). There are however some additional things to keep in mind. The configuration for the Gaufrette chunk storage should look as the following: -``` + +```yaml oneup_uploader: chunks: maxage: 86400 @@ -51,27 +54,29 @@ oneup_uploader: stream_wrapper: 'gaufrette://gallery/' ``` -> Setting the `stream_wrapper` is heavily recommended for better performance, see the reasons in the [gaufrette configuration](gaufrette_storage.md#configure-your-mappings) +> :exclamation: Setting the `stream_wrapper` is heavily recommended for better performance, see the reasons in the [gaufrette configuration](gaufrette_storage.md#configure-your-mappings) -As you can see there are is a new option, `prefix`. It represents the directory +As you can see there are is an option, `prefix`. It represents the directory *relative* to the filesystem's directory which the chunks are stored in. Gaufrette won't allow it to be outside of the filesystem. - -> You can only use stream capable filesystems for the chunk storage, at the time of this writing -only the Local filesystem is capable of streaming directly. - This will give you a better structured directory, as the chunk's folders and the uploaded files won't mix with each other. -> You can set it to an empty string (`''`), if you don't need it. Otherwise it defaults to `chunks`. +You can set it to an empty string (`''`), if you don't need it. Otherwise it defaults to `chunks`. + +> :exclamation: You can only use stream capable filesystems for the chunk storage, at the time of this writing +only the Local filesystem is capable of streaming directly. The chunks will be read directly from the temporary directory and appended to the already existing part on the given filesystem, -resulting in only 1 read and 1 write operation. +resulting in only one single read and one single write operation. + +> :exclamation: Do not use a Gaufrette filesystem for the chunk storage and a local filesystem for the mapping. This is not possible to check during container setup and will throw unexpected errors at runtime! You can achieve the biggest improvement if you use the same filesystem as your storage. If you do so, the assembled file only has to be moved out of the chunk directory, which takes no time on a local filesystem. > The load distribution is forcefully turned on, if you use Gaufrette as the chunk storage. +See the [Use Chunked Uploads behind Load Balancers](load_balancers.md) section in the documentation for a full configuration example. ## Clean up diff --git a/Resources/doc/load_balancers.md b/Resources/doc/load_balancers.md index 0667b94..c178600 100644 --- a/Resources/doc/load_balancers.md +++ b/Resources/doc/load_balancers.md @@ -3,4 +3,39 @@ Use Chunked Uploads behind Load Balancers If you want to use Chunked Uploads behind load balancers that is not configured to use sticky sessions you'll eventually end up with a bunch of chunks on every instance and the bundle is not able to reassemble the file on the server. -You can avoid this problem by using Gaufrette as an abstract filesystem. \ No newline at end of file +You can avoid this problem by using Gaufrette as an abstract filesystem. Check the following configuration as an example. + +```yaml +knp_gaufrette: + adapters: + gallery: + local: + directory: %kernel.root_dir%/../web/uploads + create: true + + filesystems: + gallery: + adapter: gallery + + stream_wrapper: ~ + +oneup_uploader: + chunks: + storage: + type: gaufrette + filesystem: gaufrette.gallery_filesystem + stream_wrapper: gaufrette://gallery/ + + mappings: + gallery: + frontend: fineuploader + storage: + type: gaufrette + filesystem: gaufrette.gallery_filesystem +``` + +> :exclamation: Event though it is possible to use two different Gaufrette filesystems - one for the the chunk storage - and one for the mapping, it is not recommended. + +> :exclamation: Do not use a Gaufrette filesystem for the chunk storage and a local filesystem one for the mapping. This is not possible to check during configuration and will throw unexpected errors! + +Using Gaufrette filesystems for chunked upload directories has some limitations. It is highly recommended to use a `Local` Gaufrette adapter as it is the only one that is able to `rename` a file but `move` it. Especially when working with bigger files this can have serious perfomance advantages as this way the file doesn't have to be moved entirely to memory! \ No newline at end of file
0
8e4ebe40a5818e9d4cecf0550814f60941a3a6b3
1up-lab/OneupUploaderBundle
Started documentation of Gaufrette Storage. Still needs some more texting.
commit 8e4ebe40a5818e9d4cecf0550814f60941a3a6b3 Author: Jim Schmid <[email protected]> Date: Sun Apr 7 20:21:36 2013 +0200 Started documentation of Gaufrette Storage. Still needs some more texting. diff --git a/Resources/doc/gaufrette_storage.md b/Resources/doc/gaufrette_storage.md new file mode 100644 index 0000000..9dc6b51 --- /dev/null +++ b/Resources/doc/gaufrette_storage.md @@ -0,0 +1,55 @@ +Use Gaufrette as Storage layer +============================== + +Gaufrette is an abstract storage layer you can use to store your uploaded files. From the _Why use Gaufrette_ section on [their Repository](https://github.com/KnpLabs/Gaufrette): + +> The filesystem abstraction layer permits you to develop your application without the need to know were all those medias will be stored and how. +> +> Another advantage of this is the possibility to update the files location without any impact on the code apart from the definition of your filesystem. In example, if your project grows up very fast and if your server reaches its limits, you can easily move your medias in an Amazon S3 server or any other solution. + +In order to use Gaufrette with OneupUploaderBundle, be sure to follow these steps: + +## Install KnpGaufretteBundle + +Add the KnpGaufretteBundle to your composer.json file. + +```js +{ + "require": { + "knplabs/knp-gaufrette-bundle": "0.1.*" + } +} +``` + +And update your dependencies through composer. + + $> php composer.phar update knplabs/knp-gaufrette-bundle + +After installing, enable the bundle in your AppKernel: + +``` php +<?php +// app/AppKernel.php + +public function registerBundles() +{ + $bundles = array( + // ... + new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), + ); +} +``` + +## Configure your Filesystems + +## Configure your mappings + +```yml +oneup_uploader: + mappings: + gallery: + storage: + type: gaufrette + filesystem: gaufrette.gallery_filesystem +``` + diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 021561b..860ea15 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -104,7 +104,7 @@ some more advanced features. * [Enable chunked uploads](chunked_uploads.md) * Using the Orphanage -* Use Gaufrette as storage layer +* [Use Gaufrette as storage layer](gaufrette_storage.md) * [Include your own Namer](custom_namer.md) * Testing this bundle * [Configuration Reference](configuration_reference.md) \ No newline at end of file
0
c0d9cce3e2c5b2ecb6253d719d8471049451ae2b
1up-lab/OneupUploaderBundle
Added documentation headers to ChunkManagerInterface.
commit c0d9cce3e2c5b2ecb6253d719d8471049451ae2b Author: Jim Schmid <[email protected]> Date: Tue Aug 13 09:36:44 2013 +0200 Added documentation headers to ChunkManagerInterface. diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php index 1ba2c15..0991a3e 100644 --- a/Uploader/Chunk/ChunkManagerInterface.php +++ b/Uploader/Chunk/ChunkManagerInterface.php @@ -6,9 +6,50 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; interface ChunkManagerInterface { - public function clear(); + /** + * Adds a new Chunk to a given uuid. + * + * @param string $uuid + * @param int $index + * @param UploadedFile $chunk + * @param string $original The file name of the original file + * + * @return File The moved chunk file. + */ public function addChunk($uuid, $index, UploadedFile $chunk, $original); + + /** + * Assembles the given chunks and return the resulting file. + * + * @param \IteratorAggregate $chunks + * @param bool $removeChunk Remove the chunk file once its assembled. + * @param bool $renameChunk Rename the chunk file once its assembled. + * + * @return File + */ public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true, $renameChunk = false); - public function cleanup($path); + + /** + * Get chunks associated with the given uuid. + * + * @param string $uuid + * + * @return Finder A finder instance + */ public function getChunks($uuid); + + /** + * Clean a given path. + * + * @param string $path + * @return bool + */ + public function cleanup($path); + + /** + * Clears the chunk manager directory. Remove all files older than the configured maxage. + * + * @return void + */ + public function clear(); }
0
6102b3ad676f9e935506e7bac323c93b6f68e322
1up-lab/OneupUploaderBundle
Removed old test versions
commit 6102b3ad676f9e935506e7bac323c93b6f68e322 Author: David Greminger <[email protected]> Date: Tue Sep 19 13:04:19 2017 +0200 Removed old test versions diff --git a/.travis.yml b/.travis.yml index f9876e0..15534ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,14 @@ language: php php: - - 5.4 - - 5.5 - - 5.6 - 7.0 - 7.1 - - hhvm env: - - SYMFONY_VERSION=2.4.* - SYMFONY_VERSION=2.7.* - SYMFONY_VERSION=2.8.* + - SYMFONY_VERSION=3.3.* + - SYMFONY_VERSION=dev-master cache: directories: @@ -19,27 +16,8 @@ cache: matrix: allow_failures: - - php: hhvm - - php: 7.0 - - php: 7.1 - env: SYMFONY_VERSION=dev-master - include: - - php: 5.6 - env: SYMFONY_VERSION=2.4.* - - php: 5.6 - env: SYMFONY_VERSION=2.5.* - - php: 5.6 - env: SYMFONY_VERSION=2.6.* - - php: 5.6 - env: SYMFONY_VERSION=2.7.* - - php: 5.6 - env: SYMFONY_VERSION=2.8.* - - php: 5.6 - env: SYMFONY_VERSION=3.0.* - - php: 5.6 - env: SYMFONY_VERSION=dev-master - before_install: - composer selfupdate
0
bde473d4cadabc752e072ae8487bf8d9bd429d9c
1up-lab/OneupUploaderBundle
Merge pull request #233 from darthf1/patch-1 Update frontend_dropzone.md
commit bde473d4cadabc752e072ae8487bf8d9bd429d9c (from 7c0f4bb6c13c6f73bfe62b55d3c564f8e526a517) Merge: 7c0f4bb 4edc094 Author: David Greminger <[email protected]> Date: Wed Mar 2 15:23:01 2016 +0100 Merge pull request #233 from darthf1/patch-1 Update frontend_dropzone.md diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md index 66fc318..b0fd9b1 100644 --- a/Resources/doc/frontend_dropzone.md +++ b/Resources/doc/frontend_dropzone.md @@ -4,7 +4,7 @@ Use Dropzone in your Symfony2 application Download [Dropzone](http://www.dropzonejs.com/) and include it in your template. Connect the `action` property of the form to the dynamic route `_uploader_{mapping_name}`. ```html -<script type="text/javascript" src="https://rawgithub.com/enyo/dropzone/master/downloads/dropzone.js"></script> +<script type="text/javascript" src="https://raw.githubusercontent.com/enyo/dropzone/master/dist/dropzone.js"></script> <form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone"> </form>
0
8a373edbe673a6478a329a7cc1f7fedc251bd49b
1up-lab/OneupUploaderBundle
Add compiler pass (#323)
commit 8a373edbe673a6478a329a7cc1f7fedc251bd49b Author: dev-lddw <[email protected]> Date: Mon Jul 16 12:42:44 2018 +0200 Add compiler pass (#323) diff --git a/DependencyInjection/Compiler/OneUpPass.php b/DependencyInjection/Compiler/OneUpPass.php new file mode 100644 index 0000000..2fff4b7 --- /dev/null +++ b/DependencyInjection/Compiler/OneUpPass.php @@ -0,0 +1,43 @@ +<?php + +namespace Oneup\UploaderBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +class OneUpPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + // Find autowired controllers + $autowired_controllers = $container->findTaggedServiceIds('controller.service_arguments'); + + // Find OneUp controllers + $controllers = $container->findTaggedServiceIds('oneup_uploader.controller'); + foreach($controllers as $id => $tags) { + + // Get fully qualified name of service + $fqdn = $container->getDefinition($id)->getClass(); + if(isset($autowired_controllers[$fqdn])) { + + // Retrieve auto wired controller + $autowired_definition = $container->getDefinition($fqdn); + + // Retrieve arguments from OneUp controller + $arguments = $container->getDefinition($id)->getArguments(); + + // Add arguments to auto wired controller + if(empty($autowired_definition->getArguments())) { + foreach($arguments as $argument) { + $autowired_definition->addArgument($argument); + } + } + + // Remove autowire + if(method_exists($autowired_definition, 'setAutowired')) { + $autowired_definition->setAutowired(false); + } + } + } + } +} \ No newline at end of file diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 4ed42dd..6285220 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -122,6 +122,7 @@ class OneupUploaderExtension extends Extension ->addArgument($key) ->addTag('oneup_uploader.routable', ['type' => $key]) + ->addTag('oneup_uploader.controller') ; return $controllerName; diff --git a/OneupUploaderBundle.php b/OneupUploaderBundle.php index 2eaf18f..66e21b9 100644 --- a/OneupUploaderBundle.php +++ b/OneupUploaderBundle.php @@ -3,7 +3,14 @@ namespace Oneup\UploaderBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Oneup\UploaderBundle\DependencyInjection\Compiler\OneUpPass; class OneupUploaderBundle extends Bundle { -} + public function build(ContainerBuilder $container) + { + parent::build($container); + $container->addCompilerPass(new OneUpPass()); + } +} \ No newline at end of file
0
f32a6d0df302cea98799f445590077846aa6630e
1up-lab/OneupUploaderBundle
Introducing abstract controllers.
commit f32a6d0df302cea98799f445590077846aa6630e Author: Jim Schmid <[email protected]> Date: Tue Apr 9 23:22:56 2013 +0200 Introducing abstract controllers. diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php new file mode 100644 index 0000000..d659cf6 --- /dev/null +++ b/Controller/AbstractChunkedController.php @@ -0,0 +1,51 @@ +<?php + +namespace Oneup\UploaderBundle\Controller; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Controller\AbstractController; + +abstract class AbstractChunkedController extends AbstractController +{ + abstract protected function parseChunkedRequest(Request $request); + + protected function handleChunkedUpload(UploadedFile $file) + { + // get basic container stuff + $request = $this->container->get('request'); + $chunkManager = $this->container->get('oneup_uploader.chunk_manager'); + + // reset uploaded to always have a return value + $uploaded = null; + + // get information about this chunked request + list($last, $uuid, $index, $orig) = $this->parseChunkedRequest($request); + + $chunkManager->addChunk($uuid, $index, $file, $orig); + + // if all chunks collected and stored, proceed + // with reassembling the parts + if($last) + { + // we'll take the first chunk and append the others to it + // this way we don't need another file in temporary space for assembling + $chunks = $chunkManager->getChunks($uuid); + + // assemble parts + $assembled = $chunkManager->assembleChunks($chunks); + $path = $assembled->getPath(); + + // create a temporary uploaded file to meet the interface restrictions + $uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true); + + // validate this entity and upload on success + $this->validate($uploadedFile); + $uploaded = $this->handleUpload($uploadedFile); + + $chunkManager->cleanup($path); + } + + return $uploaded; + } +} \ No newline at end of file diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php new file mode 100644 index 0000000..60800cf --- /dev/null +++ b/Controller/AbstractController.php @@ -0,0 +1,82 @@ +<?php + +namespace Oneup\UploaderBundle\Controller; + +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\File\Exception\UploadException; +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; + +use Oneup\UploaderBundle\UploadEvents; +use Oneup\UploaderBundle\Event\PostPersistEvent; +use Oneup\UploaderBundle\Event\PostUploadEvent; +use Oneup\UploaderBundle\Controller\UploadControllerInterface; +use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; +use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; +use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; + +abstract class AbstractController implements UploadControllerInterface +{ + protected $container; + protected $storage; + protected $config; + protected $type; + + public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type) + { + $this->container = $container; + $this->storage = $storage; + $this->config = $config; + $this->type = $type; + } + + protected function handleUpload(UploadedFile $file) + { + $this->validate($file); + + // no error happend, proceed + $namer = $this->container->get($this->config['namer']); + $name = $namer->name($file); + + // perform the real upload + $uploaded = $this->storage->upload($file, $name); + + return $uploaded; + } + + protected function dispatchEvents($uploaded, ResponseInterface $response) + { + $request = $this->container->get('request'); + + $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config); + $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); + + if(!$this->config['use_orphanage']) + { + // dispatch post upload event + $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config); + $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); + } + } + + protected function validate(UploadedFile $file) + { + // check if the file size submited by the client is over the max size in our config + if($file->getClientSize() > $this->config['max_size']) + throw new UploadException('error.maxsize'); + + $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); + + // if this mapping defines at least one type of an allowed extension, + // test if the current is in this array + if(count($this->config['allowed_extensions']) > 0 && !in_array($extension, $this->config['allowed_extensions'])) + throw new UploadException('error.whitelist'); + + // check if the current extension is mentioned in the disallowed types + // and if so, throw an exception + if(count($this->config['disallowed_extensions']) > 0 && in_array($extension, $this->config['disallowed_extensions'])) + throw new UploadException('error.blacklist'); + + } +} \ No newline at end of file diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php index 438bd08..a4f4d56 100644 --- a/Controller/BlueimpController.php +++ b/Controller/BlueimpController.php @@ -6,29 +6,17 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\File\Exception\UploadException; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; use Oneup\UploaderBundle\UploadEvents; use Oneup\UploaderBundle\Event\PostPersistEvent; use Oneup\UploaderBundle\Event\PostUploadEvent; -use Oneup\UploaderBundle\Controller\UploadControllerInterface; +use Oneup\UploaderBundle\Controller\AbstractController; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; -class BlueimpController implements UploadControllerInterface +class BlueimpController extends AbstractChunkedController { - protected $container; - protected $storage; - protected $config; - protected $type; - - public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type) - { - $this->container = $container; - $this->storage = $storage; - $this->config = $config; - $this->type = $type; - } - public function upload() { $request = $this->container->get('request'); @@ -47,23 +35,13 @@ class BlueimpController implements UploadControllerInterface try { $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file); - - $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config); - $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); - - if(!$this->config['use_orphanage']) - { - // dispatch post upload event - $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config); - $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); - } + + // dispatch POST_PERSIST AND POST_UPLOAD events + $this->dispatchEvents($uploaded, $response); } catch(UploadException $e) { - $response->setSuccess(false); - $response->setError($translator->trans($e->getMessage(), array(), 'OneupUploaderBundle')); - - // an error happended, return this error message. + // return nothing return new JsonResponse(array()); } } @@ -71,33 +49,15 @@ class BlueimpController implements UploadControllerInterface return new JsonResponse($response->assemble()); } - protected function handleUpload(UploadedFile $file) + protected function parseChunkedRequest(Request $request) { - $this->validate($file); - - // no error happend, proceed - $namer = $this->container->get($this->config['namer']); - $name = $namer->name($file); - - // perform the real upload - $uploaded = $this->storage->upload($file, $name); - - return $uploaded; - } - - protected function handleChunkedUpload(UploadedFile $file) - { - $request = $this->container->get('request'); $session = $this->container->get('session'); - $chunkManager = $this->container->get('oneup_uploader.chunk_manager'); $headerRange = $request->headers->get('content-range'); $attachmentName = rawurldecode(preg_replace('/(^[^"]+")|("$)/', '', $request->headers->get('content-disposition'))); // split the header string to the appropriate parts list($tmp, $startByte, $endByte, $totalBytes) = preg_split('/[^0-9]+/', $headerRange); - $uploaded = null; - // getting information about chunks // note: We don't have a chance to get the last $total // correct. This is due to the fact that the $size variable @@ -116,50 +76,6 @@ class BlueimpController implements UploadControllerInterface $uuid = md5(sprintf('%s.%s', $attachmentName, $session->getId())); $orig = $attachmentName; - $chunkManager->addChunk($uuid, $index, $file, $orig); - - // if all chunks collected and stored, proceed - // with reassembling the parts - if(($endByte + 1) == $totalBytes) - { - // we'll take the first chunk and append the others to it - // this way we don't need another file in temporary space for assembling - $chunks = $chunkManager->getChunks($uuid); - - // assemble parts - $assembled = $chunkManager->assembleChunks($chunks); - $path = $assembled->getPath(); - - // create a temporary uploaded file to meet the interface restrictions - $uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true); - - // validate this entity and upload on success - $this->validate($uploadedFile); - $uploaded = $this->handleUpload($uploadedFile); - - $chunkManager->cleanup($path); - } - - return $uploaded; - } - - protected function validate(UploadedFile $file) - { - // check if the file size submited by the client is over the max size in our config - if($file->getClientSize() > $this->config['max_size']) - throw new UploadException('error.maxsize'); - - $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); - - // if this mapping defines at least one type of an allowed extension, - // test if the current is in this array - if(count($this->config['allowed_extensions']) > 0 && !in_array($extension, $this->config['allowed_extensions'])) - throw new UploadException('error.whitelist'); - - // check if the current extension is mentioned in the disallowed types - // and if so, throw an exception - if(count($this->config['disallowed_extensions']) > 0 && in_array($extension, $this->config['disallowed_extensions'])) - throw new UploadException('error.blacklist'); - + return array($last, $uuid, $index, $orig); } } \ No newline at end of file
0
bc015a4b7b1d588b604be57da934a9b5a5ff3290
1up-lab/OneupUploaderBundle
Merge pull request #246 from deviprsd21/master Fix typo (see #237)
commit bc015a4b7b1d588b604be57da934a9b5a5ff3290 (from 70fdfdbdf72642d382ce62d966d2079cc3a39061) Merge: 70fdfdb 0142800 Author: David Greminger <[email protected]> Date: Wed May 4 11:43:58 2016 +0200 Merge pull request #246 from deviprsd21/master Fix typo (see #237) diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index c577309..2aa007b 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -82,6 +82,6 @@ See the [Use Chunked Uploads behind Load Balancers](load_balancers.md) section i The ChunkManager can be forced to clean up old and orphanaged chunks by using the command provided by the OneupUploaderBundle. - $> php app/console oneup:uploader:clean-chunks + $> php app/console oneup:uploader:clear-chunks This parameter will clean all chunk files older than the `maxage` value in your configuration.
0
c30b5a51b544533ace43d8bbbef3c8c4332e593c
1up-lab/OneupUploaderBundle
Namers don't know about the directory prefix, so it won't be passed to them.
commit c30b5a51b544533ace43d8bbbef3c8c4332e593c Author: Jim Schmid <[email protected]> Date: Sat Apr 6 10:25:46 2013 +0200 Namers don't know about the directory prefix, so it won't be passed to them. diff --git a/Uploader/Naming/NamerInterface.php b/Uploader/Naming/NamerInterface.php index 7bbf4d0..cf6fa30 100644 --- a/Uploader/Naming/NamerInterface.php +++ b/Uploader/Naming/NamerInterface.php @@ -6,5 +6,5 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; interface NamerInterface { - public function name(UploadedFile $file, $prefix = null); + public function name(UploadedFile $file); } \ No newline at end of file diff --git a/Uploader/Naming/UniqidNamer.php b/Uploader/Naming/UniqidNamer.php index 07e04d9..1063205 100644 --- a/Uploader/Naming/UniqidNamer.php +++ b/Uploader/Naming/UniqidNamer.php @@ -9,8 +9,6 @@ class UniqidNamer implements NamerInterface { public function name(UploadedFile $file, $prefix = null) { - $prefix = !is_null($prefix) ? $prefix . '/' : ''; - - return sprintf('%s%s.%s', $prefix, uniqid(), $file->guessExtension()); + return sprintf('%s.%s', uniqid(), $file->guessExtension()); } } \ No newline at end of file
0
489ea8fe07702e92c548abebd022c385e0382728
1up-lab/OneupUploaderBundle
Introducing Namers. (inluding an Interface and a simple uniqid-Implementation)
commit 489ea8fe07702e92c548abebd022c385e0382728 Author: Jim Schmid <[email protected]> Date: Tue Mar 12 12:54:13 2013 +0100 Introducing Namers. (inluding an Interface and a simple uniqid-Implementation) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a238a49..afbd956 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -44,7 +44,7 @@ class Configuration implements ConfigurationInterface ->scalarNode('storage')->isRequired()->end() ->booleanNode('use_orphanage')->defaultFalse()->end() ->scalarNode('action')->defaultNull()->end() - ->scalarNode('namer')->defaultNull()->end() + ->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end() ->end() ->end() ->end() diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 24a24b2..11344b6 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -6,6 +6,7 @@ <parameters> <parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter> <parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter> + <parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter> <parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter> <parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter> </parameters> @@ -19,6 +20,9 @@ <argument>%oneup_uploader.orphanage%</argument> </service> + <!-- namer --> + <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" /> + <!-- controller --> <service id="oneup_uploader.controller" class="%oneup_uploader.controller.class%"> <argument>%oneup_uploader.mappings%</argument> diff --git a/Uploader/Naming/NamerInterface.php b/Uploader/Naming/NamerInterface.php new file mode 100644 index 0000000..4a7882c --- /dev/null +++ b/Uploader/Naming/NamerInterface.php @@ -0,0 +1,10 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Naming; + +use Symfony\Component\HttpFoundation\File\UploadedFile; + +interface NamerInterface +{ + public function name(UploadedFile $file, array $mapping = array()); +} \ No newline at end of file diff --git a/Uploader/Naming/UniqidNamer.php b/Uploader/Naming/UniqidNamer.php new file mode 100644 index 0000000..c9b918f --- /dev/null +++ b/Uploader/Naming/UniqidNamer.php @@ -0,0 +1,14 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Naming; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; + +class UniqidNamer implements NamerInterface +{ + public function name(UploadedFile $file, array $mapping = array()) + { + return sprintf('%s.%s', uniqid(), $file->guessExtension()); + } +} \ No newline at end of file
0
bf58310922b949d9226572b7183a8d4b4cc73509
1up-lab/OneupUploaderBundle
Fix RuntimeException: Could not read key content bug When uploading a file with GaufretteStorage the file should be open for writing, not appending. This makes sense for multiple reasons: 1) Since if we are uploading the same file twice, we likely want to overwrite it, not append data to the existing file (much like how 'cp' works on file systems). 2) When uploading to Amazon S3, there is a condition where Gaufrette\Stream\InMemoryBuffer::open thinks the file exists, but calling `$this->filesystem->read($this->key);` throws an `RuntimeException: Could not read key content` exception. Using a write mode instead of append will pass the impliesExistingContentDeletion test and avoid the read.
commit bf58310922b949d9226572b7183a8d4b4cc73509 Author: Matt Farmer <[email protected]> Date: Tue Jun 11 10:39:14 2013 -0700 Fix RuntimeException: Could not read key content bug When uploading a file with GaufretteStorage the file should be open for writing, not appending. This makes sense for multiple reasons: 1) Since if we are uploading the same file twice, we likely want to overwrite it, not append data to the existing file (much like how 'cp' works on file systems). 2) When uploading to Amazon S3, there is a condition where Gaufrette\Stream\InMemoryBuffer::open thinks the file exists, but calling `$this->filesystem->read($this->key);` throws an `RuntimeException: Could not read key content` exception. Using a write mode instead of append will pass the impliesExistingContentDeletion test and avoid the read. diff --git a/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php new file mode 100644 index 0000000..cfcf85d --- /dev/null +++ b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php @@ -0,0 +1,81 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Uploader\Storage; + +use \AmazonS3 as AmazonClient; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Gaufrette\Filesystem as GaufretteFilesystem; +use Gaufrette\Adapter\AmazonS3 as S3Adapter; +use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage; + +class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase +{ + protected $directory; + protected $storage; + + public function setUp() + { + if( + "" == getenv('AWS_ACCESS_KEY_ID') || + "" == getenv('AWS_SECRET_ACCESS_KEY') || + "" == getenv('AWS_BUCKET') + ) { + $this->markTestSkipped('Missing AWS_* ENV variables.'); + } + + $this->prefix = 'someObscureStorage'; + $this->directory = sys_get_temp_dir() .'/'. $this->prefix; + if(!file_exists($this->directory)) { + mkdir($this->directory); + } + + // create temporary file + $this->file = tempnam($this->directory, 'uploader'); + + $pointer = fopen($this->file, 'w+'); + fwrite($pointer, str_repeat('A', 1024), 1024); + fclose($pointer); + + $service = new AmazonClient(array( + 'key' => getenv('AWS_ACCESS_KEY_ID'), + 'secret' => getenv('AWS_SECRET_ACCESS_KEY'), + )); + $adapter = new S3Adapter($service, getenv('AWS_BUCKET')); + $this->filesystem = new GaufretteFilesystem($adapter); + + $this->storage = new GaufretteStorage($this->filesystem); + } + + public function testUpload() + { + $payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true); + $this->storage->upload($payload, $this->prefix .'/notsogrumpyanymore.jpeg'); + + $files = $this->filesystem->listKeys($this->prefix); + + // on Amazon S3, if it exists, it is considered a directory + $this->assertCount(2, $files['keys']); + + foreach($files['keys'] as $filename) + { + if($filename === $this->prefix) { + // ignore the prefix directory + continue; + } + $this->assertEquals($this->prefix. '/notsogrumpyanymore.jpeg', $filename); + $this->assertEquals(1024, strlen($this->filesystem->read($filename))); + } + } + + public function tearDown() + { + $files = $this->filesystem->listKeys($this->prefix); + foreach($files['keys'] as $filename) + { + if($this->filesystem->has($filename)) { + $this->filesystem->delete($filename); + } + } + } +} diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index 5823d50..47306ab 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -38,7 +38,7 @@ class GaufretteStorage implements StorageInterface $this->filesystem->write($path, '', true); $src->open(new StreamMode('rb+')); - $dst->open(new StreamMode('ab+')); + $dst->open(new StreamMode('wb+')); while(!$src->eof()) { diff --git a/composer.json b/composer.json index ac41496..e3ca30d 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ }, "require-dev": { + "amazonwebservices/aws-sdk-for-php": "1.5.*", "knplabs/gaufrette": "0.2.*@dev", "symfony/class-loader": "2.*", "symfony/security-bundle": "2.*",
0
1d78995ac53f647581c3e79dabe8db4e39e9cab7
1up-lab/OneupUploaderBundle
Removed the rest of unnesseccary delete-functionality stuff.
commit 1d78995ac53f647581c3e79dabe8db4e39e9cab7 Author: Jim Schmid <[email protected]> Date: Wed Mar 27 18:16:39 2013 +0100 Removed the rest of unnesseccary delete-functionality stuff. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index 934de3e..c4b8570 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -13,7 +13,6 @@ use Symfony\Component\Finder\Finder; use Oneup\UploaderBundle\UploadEvents; use Oneup\UploaderBundle\Event\PostPersistEvent; use Oneup\UploaderBundle\Event\PostUploadEvent; -use Oneup\UploaderBundle\Event\PostDeleteEvent; use Oneup\UploaderBundle\Controller\UploadControllerInterface; use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; diff --git a/Event/PostDeleteEvent.php b/Event/PostDeleteEvent.php deleted file mode 100644 index 0528225..0000000 --- a/Event/PostDeleteEvent.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace Oneup\UploaderBundle\Event; - -use Symfony\Component\EventDispatcher\Event; -use Symfony\Component\HttpFoundation\Request; - -class PostDeleteEvent extends Event -{ - protected $requets; - protected $uuid; - protected $type; - - public function __construct(Request $request, $uuid, $type) - { - $this->request = $request; - $this->uuid = $uuid; - $this->type = $type; - } - - public function getRequest() - { - return $this->request; - } - - public function getUuid() - { - return $this->uuid; - } - - public function getType() - { - return $this->type; - } -} \ No newline at end of file diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 63abc4e..66ba880 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -12,7 +12,6 @@ <parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter> <parameter key="oneup_uploader.storage.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter> <parameter key="oneup_uploader.listener.orphanage.class">Oneup\UploaderBundle\EventListener\OrphanageListener</parameter> - <parameter key="oneup_uploader.listener.deletable.class">Oneup\UploaderBundle\EventListener\DeletableListener</parameter> </parameters> <services> diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index f0a7430..66b074f 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -8,17 +8,14 @@ use Gaufrette\StreamMode; use Gaufrette\Filesystem; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; -use Oneup\UploaderBundle\Uploader\Deletable\DeletableManagerInterface; class GaufretteStorage implements StorageInterface { protected $filesystem; - protected $deletableManager; - public function __construct(Filesystem $filesystem, DeletableManagerInterface $deletableManager) + public function __construct(Filesystem $filesystem) { $this->filesystem = $filesystem; - $this->deletableManager = $deletableManager; } public function upload(File $file, $name = null) @@ -49,29 +46,4 @@ class GaufretteStorage implements StorageInterface return $this->filesystem->get($name); } - - public function remove($type, $uuid) - { - try - { - // get associated file path - $name = $this->deletableManager->getFile($type, $uuid); - - if($this->filesystem->has($name)) - { - $this->filesystem->delete($name); - } - - // delete this reference anyway - $this->deletableManager->removeFile($type, $uuid); - } - catch(\Exception $e) - { - // whoopsi, something went terribly wrong - // better leave this method now and never look back - return false; - } - - return true; - } } \ No newline at end of file
0
a32bc98019abfd51531d08cc79be19f849d87b84
1up-lab/OneupUploaderBundle
Use r+b instead of rb+ mode (#304)
commit a32bc98019abfd51531d08cc79be19f849d87b84 Author: Lctrs <[email protected]> Date: Mon Dec 18 13:41:59 2017 +0100 Use r+b instead of rb+ mode (#304) diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php index c3783ac..401a8d8 100644 --- a/Uploader/Storage/FlysystemStorage.php +++ b/Uploader/Storage/FlysystemStorage.php @@ -38,7 +38,7 @@ class FlysystemStorage implements StorageInterface $path = null === $path ? $name : sprintf('%s/%s', $path, $name); if ($file instanceof FilesystemFile) { - $stream = fopen($file->getPathname(), 'rb+'); + $stream = fopen($file->getPathname(), 'r+b'); $this->filesystem->putStream($path, $stream, array( 'mimetype' => $file->getMimeType() ));
0
147388f69ed1b5d5fa8b91e2c039fb7e8deb0093
1up-lab/OneupUploaderBundle
Revert "made docs a bit nicer with a check" This reverts commit 5e789d8b759d1977643a5ac99b3291fd30d866f5.
commit 147388f69ed1b5d5fa8b91e2c039fb7e8deb0093 Author: mitom <[email protected]> Date: Mon Oct 14 21:09:25 2013 +0200 Revert "made docs a bit nicer with a check" This reverts commit 5e789d8b759d1977643a5ac99b3291fd30d866f5. diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index a3f55dc..c017bdc 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -63,12 +63,6 @@ class OneupUploaderExtension extends Extension protected function processMapping($key, &$mapping) { - if ($this->config['chunks']['storage']['type'] === 'gaufrette') { - if ($mapping['storage']['type'] !== 'gaufrette') { - throw new \InvalidArgumentException('If you use a gaufrette based chunk storage, you may only use gaufrette based storages too.'); - } - } - $mapping['max_size'] = $mapping['max_size'] < 0 ? $this->getMaxUploadSize($mapping['max_size']) : $mapping['max_size'] diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index 2f53fb7..fd6d87a 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -69,7 +69,7 @@ only the Local filesystem is capable of streaming directly. The chunks will be read directly from the temporary directory and appended to the already existing part on the given filesystem, resulting in only one single read and one single write operation. -> :exclamation: If you use a gaufrette filesystem as chunk storage, you may only use gaufrette filesystems in your mappings too! +> :exclamation: Do not use a Gaufrette filesystem for the chunk storage and a local filesystem for the mapping. This is not possible to check during container setup and will throw unexpected errors at runtime! You can achieve the biggest improvement if you use the same filesystem as your storage. If you do so, the assembled file only has to be moved out of the chunk directory, which takes no time on a local filesystem.
0
63bd03db2f5a8183573f2c55ee544b50ffea8057
1up-lab/OneupUploaderBundle
ErrorHandler documentation.
commit 63bd03db2f5a8183573f2c55ee544b50ffea8057 Author: Jim Schmid <[email protected]> Date: Mon Jul 15 11:48:58 2013 +0200 ErrorHandler documentation. diff --git a/README.md b/README.md index f72f219..3737275 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,9 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- -* Event names [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be) in Version **0.9.3**, update your EventListener accordingly. +* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md). * Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_logic.md#using-chunked-uploads). +* Event names [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be) in Version **0.9.3**, update your EventListener accordingly. License ------- diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index 144c091..52edb2d 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -29,6 +29,7 @@ oneup_uploader: disallowed_extensions: [] allowed_mimetypes: [] disallowed_mimetypes: [] + error_handler: oneup_uploader.error_handler.noop max_size: 9223372036854775807 use_orphanage: false enable_progress: false diff --git a/Resources/doc/custom_error_handler.md b/Resources/doc/custom_error_handler.md new file mode 100644 index 0000000..baf4507 --- /dev/null +++ b/Resources/doc/custom_error_handler.md @@ -0,0 +1,45 @@ +Error Handlers +============== + +Since version **0.9.6** of this bundle, the error management is using special error handler services. Its main purpose is to recieve an `UploadException` and the `Response` object and handle the error according to the frontend specification. You can define an own error handler for each entry in your configuration. The default handler is the so called `NoopErrorHandler` which does nothing, when recieving an exception. + +To create your own error handler, implement the `ErrorHandlerInterface` and add your custom logic. + +```php +<?php + +namespace Acme\DemoBundle\ErrorHandler; + +use Symfony\Component\HttpFoundation\File\Exception\UploadException; +use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface; +use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; + +class CustomErrorHandler implements ErrorHandlerInterface +{ + public function addException(ResponseInterface $response, UploadException $exception) + { + $message = $exception->getErrorMessage(); + $response['error'] = $message; + } +} + +``` + +Define a service for your class. + +```xml +<services> + <service id="acme_demo.custom_error_handler" class="Acme\DemoBundle\ErrorHandler\CustomErrorHandler" /> +</services> +``` + +And configure the mapping to use your shiny new service. + +```yml +oneup_uploader: + mappings: + gallery: + error_handler: acme_demo.custom_error_handler +``` + +**Note**: As of [9dbd905](https://github.com/1up-lab/OneupUploaderBundle/commit/9dbd9056dfe403ce6f1273d2d75fe814d517731a) only the `BlueimpErrorHandler` is implemented. If you know how to implement the error handlers for the other supported frontends, please create a pull request or drop me a note. \ No newline at end of file diff --git a/Resources/doc/index.md b/Resources/doc/index.md index d5b5721..4080132 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -118,12 +118,13 @@ some more advanced features. * [Using the Orphanage](orphanage.md) * [Use Gaufrette as storage layer](gaufrette_storage.md) * [Include your own Namer](custom_namer.md) -* [Testing this bundle](testing.md) +* [Use custom error handlers](custom_error_handler.md) * [Support a custom uploader](custom_uploader.md) * [Validate your uploads](custom_validator.md) * [General/Generic Events](events.md) * [Enable Session upload progress / upload cancelation](progress.md) * [Configuration Reference](configuration_reference.md) +* [Testing this bundle](testing.md) ## FAQ
0
786efca3939d9d38c78625e6e56cc047daf5e242
1up-lab/OneupUploaderBundle
Merge pull request #47 from 1up-lab/feature-dropzone-uploader Dropzone uploader
commit 786efca3939d9d38c78625e6e56cc047daf5e242 (from 44fbde3a6aaec6a7364362386b5b63907ce6688d) Merge: 44fbde3 f7b509f Author: Jim Schmid <[email protected]> Date: Wed Sep 18 03:42:15 2013 -0700 Merge pull request #47 from 1up-lab/feature-dropzone-uploader Dropzone uploader diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php new file mode 100644 index 0000000..17d6ba9 --- /dev/null +++ b/Controller/DropzoneController.php @@ -0,0 +1,29 @@ +<?php + +namespace Oneup\UploaderBundle\Controller; + +use Symfony\Component\HttpFoundation\File\Exception\UploadException; +use Symfony\Component\HttpFoundation\JsonResponse; + +use Oneup\UploaderBundle\Controller\AbstractController; +use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; + +class DropzoneController extends AbstractController +{ + public function upload() + { + $request = $this->container->get('request'); + $response = new EmptyResponse(); + $files = $this->getFiles($request->files); + + foreach ($files as $file) { + try { + $uploaded = $this->handleUpload($file, $response, $request); + } catch (UploadException $e) { + $this->errorHandler->addException($response, $e); + } + } + + return new JsonResponse($response->assemble()); + } +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1c8ec39..e18268a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -37,7 +37,7 @@ class Configuration implements ConfigurationInterface ->prototype('array') ->children() ->enumNode('frontend') - ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'custom')) + ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'dropzone', 'custom')) ->defaultValue('fineuploader') ->end() ->arrayNode('custom_frontend') diff --git a/README.md b/README.md index d7ed3fd..a8b708b 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ The OneupUploaderBundle for Symfony2 adds support for handling file uploads usin * [FancyUpload](http://digitarald.de/project/fancyupload/) * [MooUpload](https://github.com/juanparati/MooUpload) * [Plupload](http://www.plupload.com/) +* [Dropzone](http://www.dropzonejs.com/) Features included: diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml index 7bfb131..e684668 100644 --- a/Resources/config/errorhandler.xml +++ b/Resources/config/errorhandler.xml @@ -17,6 +17,7 @@ <service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.mooupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" /> </services> diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index f6c93af..39502ab 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -18,6 +18,7 @@ <parameter key="oneup_uploader.controller.fancyupload.class">Oneup\UploaderBundle\Controller\FancyUploadController</parameter> <parameter key="oneup_uploader.controller.mooupload.class">Oneup\UploaderBundle\Controller\MooUploadController</parameter> <parameter key="oneup_uploader.controller.plupload.class">Oneup\UploaderBundle\Controller\PluploadController</parameter> + <parameter key="oneup_uploader.controller.dropzone.class">Oneup\UploaderBundle\Controller\DropzoneController</parameter> </parameters> <services> diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md new file mode 100644 index 0000000..0be52b3 --- /dev/null +++ b/Resources/doc/frontend_dropzone.md @@ -0,0 +1,24 @@ +Use Dropzone in your Symfony2 application +========================================= + +Download [Dropzone](http://www.dropzonejs.com/) and include it in your template. Connect the `action` property of the form to the dynamic route `_uploader_{mapping_name}`. + +```html +<script type="text/javascript" src="https://rawgithub.com/enyo/dropzone/master/downloads/dropzone.js"></script> + +<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone"> +</form> +``` + +Configure the OneupUploaderBundle to use the correct controller: + +```yaml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + frontend: dropzone +``` + +Be sure to check out the [official manual](http://www.dropzonejs.com/) for details on the configuration. \ No newline at end of file diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 8d85022..fe69b15 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -96,7 +96,7 @@ $endpoint = $helper->endpoint('gallery'); or in a Twig template you can use the `oneup_uploader_endpoint` function: {{ oneup_uploader_endpoint('gallery') }} - + So if you take the mapping described before, the generated route name would be `_uploader_gallery`. Follow one of the listed guides to include your frontend: * [Use FineUploader](frontend_fineuploader.md) @@ -106,6 +106,7 @@ So if you take the mapping described before, the generated route name would be ` * [Use FancyUpload](frontend_fancyupload.md) * [Use MooUpload](frontend_mooupload.md) * [Use Plupload](frontend_plupload.md) +* [Use Dropzone](frontend_dropzone.md) ## Next steps diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index 43d37c3..619cebc 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -43,6 +43,21 @@ oneup_uploader: allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] + dropzone: + frontend: dropzone + storage: + directory: %kernel.root_dir%/cache/%kernel.environment%/upload + + dropzone_validation: + frontend: dropzone + max_size: 256 + storage: + directory: %kernel.root_dir%/cache/%kernel.environment%/upload + allowed_extensions: [ "ok" ] + disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] + disallowed_mimetypes: [ "image/gif" ] + yui3: frontend: yui3 storage: diff --git a/Tests/Controller/DropzoneTest.php b/Tests/Controller/DropzoneTest.php new file mode 100644 index 0000000..a5aa7d0 --- /dev/null +++ b/Tests/Controller/DropzoneTest.php @@ -0,0 +1,29 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Controller; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Tests\Controller\AbstractUploadTest; + +class DropzoneTest extends AbstractUploadTest +{ + protected function getConfigKey() + { + return 'dropzone'; + } + + protected function getRequestParameters() + { + return array(); + } + + protected function getRequestFile() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.txt', + 'text/plain', + 128 + ); + } +} diff --git a/Tests/Controller/DropzoneValidationTest.php b/Tests/Controller/DropzoneValidationTest.php new file mode 100644 index 0000000..73cb5ff --- /dev/null +++ b/Tests/Controller/DropzoneValidationTest.php @@ -0,0 +1,69 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Controller; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest; + +class DropzoneValidationTest extends AbstractValidationTest +{ + protected function getConfigKey() + { + return 'dropzone_validation'; + } + + protected function getRequestParameters() + { + return array(); + } + + protected function getOversizedFile() + { + return new UploadedFile( + $this->createTempFile(512), + 'cat.ok', + 'text/plain', + 512 + ); + } + + protected function getFileWithCorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'text/plain', + 128 + ); + } + + protected function getFileWithIncorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.fail', + 'text/plain', + 128 + ); + } + + protected function getFileWithCorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/jpg', + 128 + ); + } + + protected function getFileWithIncorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/gif', + 128 + ); + } +} diff --git a/composer.json b/composer.json index 2dfd657..37e7667 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "oneup/uploader-bundle", "type": "symfony-bundle", "description": "Handles multi file uploads in Symfony2. Features included: Chunked upload, Orphans management, Gaufrette support.", - "keywords": ["fileupload", "upload", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload"], + "keywords": ["fileupload", "upload", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload", "Dropzone"], "homepage": "http://1up.io", "license": "MIT", "authors": [
0
172b38ae024c6ecfebb0ffa7b7537eea027a849f
1up-lab/OneupUploaderBundle
Renamed class file.
commit 172b38ae024c6ecfebb0ffa7b7537eea027a849f Author: Jim Schmid <[email protected]> Date: Tue Apr 9 21:54:50 2013 +0200 Renamed class file. diff --git a/Uploader/Response/BlueimpResponse.php b/Uploader/Response/BlueimpResponse.php index 8842b6b..a7e6c26 100644 --- a/Uploader/Response/BlueimpResponse.php +++ b/Uploader/Response/BlueimpResponse.php @@ -4,8 +4,12 @@ namespace Oneup\UploaderBundle\Uploader\Response; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; -class FineUploaderResponse extends AbstractResponse +class BlueimpResponse extends AbstractResponse { + /** + * This is an array containing elements of the following type + * array(url, thumbnail_url, type, size, delete_url, delete_type) + */ protected $files; public function __construct()
0
9ec857a0224d0278712462f9ecbc52507e3d5ebe
1up-lab/OneupUploaderBundle
Allow uploading only of specific files
commit 9ec857a0224d0278712462f9ecbc52507e3d5ebe Author: Miha Vrhovnik <[email protected]> Date: Fri Jul 4 11:42:55 2014 +0200 Allow uploading only of specific files diff --git a/Uploader/Storage/FilesystemOrphanageStorage.php b/Uploader/Storage/FilesystemOrphanageStorage.php index e0026cc..03981f7 100644 --- a/Uploader/Storage/FilesystemOrphanageStorage.php +++ b/Uploader/Storage/FilesystemOrphanageStorage.php @@ -39,10 +39,12 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS return parent::upload($file, $name, $this->getPath()); } - public function uploadFiles() + public function uploadFiles(array $files = null) { try { - $files = $this->getFiles(); + if (null === $files) { + $files = $this->getFiles(); + } $return = array(); foreach ($files as $file) { diff --git a/Uploader/Storage/GaufretteOrphanageStorage.php b/Uploader/Storage/GaufretteOrphanageStorage.php index d5a9489..4be4daa 100644 --- a/Uploader/Storage/GaufretteOrphanageStorage.php +++ b/Uploader/Storage/GaufretteOrphanageStorage.php @@ -47,10 +47,12 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto return parent::upload($file, $name, $this->getPath()); } - public function uploadFiles() + public function uploadFiles(array $files = null) { try { - $files = $this->getFiles(); + if (null === $files) { + $files = $this->getFiles(); + } $return = array(); foreach ($files as $key => $file) { diff --git a/Uploader/Storage/OrphanageStorageInterface.php b/Uploader/Storage/OrphanageStorageInterface.php index 35e275f..82be28c 100644 --- a/Uploader/Storage/OrphanageStorageInterface.php +++ b/Uploader/Storage/OrphanageStorageInterface.php @@ -6,5 +6,5 @@ use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; interface OrphanageStorageInterface extends StorageInterface { - public function uploadFiles(); + public function uploadFiles(array $files = null); }
0
b330a5dc11d307f8820a7b740b8460f5346d9187
1up-lab/OneupUploaderBundle
Merge branch 'dropzone-eventhandler' of https://github.com/perk11/OneupUploaderBundle into perk11-dropzone-eventhandler
commit b330a5dc11d307f8820a7b740b8460f5346d9187 (from 568dfb13740c22de13205a702eb4b510cab0159f) Merge: 568dfb1 f420fff Author: David Greminger <[email protected]> Date: Thu Dec 10 10:42:55 2015 +0100 Merge branch 'dropzone-eventhandler' of https://github.com/perk11/OneupUploaderBundle into perk11-dropzone-eventhandler diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index a551ba8..b150214 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -183,13 +183,14 @@ abstract class AbstractController * then the content type of the response will be set to text/plain instead. * * @param mixed $data + * @param int $statusCode * * @return JsonResponse */ - protected function createSupportedJsonResponse($data) + protected function createSupportedJsonResponse($data, $statusCode = 200) { $request = $this->container->get('request'); - $response = new JsonResponse($data); + $response = new JsonResponse($data, $statusCode); $response->headers->set('Vary', 'Accept'); if (!in_array('application/json', $request->getAcceptableContentTypes())) { diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php index 2121f32..fd11420 100644 --- a/Controller/DropzoneController.php +++ b/Controller/DropzoneController.php @@ -14,11 +14,12 @@ class DropzoneController extends AbstractController $request = $this->container->get('request'); $response = new EmptyResponse(); $files = $this->getFiles($request->files); - + $statusCode = 200; foreach ($files as $file) { try { $this->handleUpload($file, $response, $request); } catch (UploadException $e) { + $statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x $this->errorHandler->addException($response, $e); $translator = $this->container->get('translator'); $message = $translator->trans($e->getMessage(), array(), 'OneupUploaderBundle'); @@ -28,6 +29,6 @@ class DropzoneController extends AbstractController } } - return $this->createSupportedJsonResponse($response->assemble()); + return $this->createSupportedJsonResponse($response->assemble(), $statusCode); } } diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml index e684668..bf580bf 100644 --- a/Resources/config/errorhandler.xml +++ b/Resources/config/errorhandler.xml @@ -6,6 +6,7 @@ <parameters> <parameter key="oneup_uploader.error_handler.noop.class">Oneup\UploaderBundle\Uploader\ErrorHandler\NoopErrorHandler</parameter> <parameter key="oneup_uploader.error_handler.blueimp.class">Oneup\UploaderBundle\Uploader\ErrorHandler\BlueimpErrorHandler</parameter> + <parameter key="oneup_uploader.error_handler.dropzone.class">Oneup\UploaderBundle\Uploader\ErrorHandler\DropzoneErrorHandler</parameter> </parameters> <services> @@ -17,7 +18,7 @@ <service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.mooupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> - <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.dropzone.class%" public="false" /> <service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" /> </services> diff --git a/Uploader/ErrorHandler/DropzoneErrorHandler.php b/Uploader/ErrorHandler/DropzoneErrorHandler.php new file mode 100755 index 0000000..5b0ad44 --- /dev/null +++ b/Uploader/ErrorHandler/DropzoneErrorHandler.php @@ -0,0 +1,19 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\ErrorHandler; + +use Exception; +use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface; +use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; + +class DropzoneErrorHandler implements ErrorHandlerInterface +{ + public function addException(AbstractResponse $response, Exception $exception) + { + $errors[] = $exception; + $message = $exception->getMessage(); + // Dropzone wants JSON with error message put into 'error' field. + // This overwrites the previous error message, so we're only displaying the last one. + $response['error'] = $message; + } +} commit b330a5dc11d307f8820a7b740b8460f5346d9187 (from f420fff5bc3ec910e925ceae15bc513b419693f2) Merge: 568dfb1 f420fff Author: David Greminger <[email protected]> Date: Thu Dec 10 10:42:55 2015 +0100 Merge branch 'dropzone-eventhandler' of https://github.com/perk11/OneupUploaderBundle into perk11-dropzone-eventhandler diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php index f8cf580..fd11420 100644 --- a/Controller/DropzoneController.php +++ b/Controller/DropzoneController.php @@ -21,6 +21,11 @@ class DropzoneController extends AbstractController } catch (UploadException $e) { $statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x $this->errorHandler->addException($response, $e); + $translator = $this->container->get('translator'); + $message = $translator->trans($e->getMessage(), array(), 'OneupUploaderBundle'); + $response = $this->createSupportedJsonResponse(array('error'=>$message )); + $response->setStatusCode(400); + return $response; } } diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 34e707d..aec580d 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -69,7 +69,7 @@ class OneupUploaderExtension extends Extension protected function processMapping($key, &$mapping) { - $mapping['max_size'] = $mapping['max_size'] < 0 ? + $mapping['max_size'] = $mapping['max_size'] < 0 || is_string($mapping['max_size']) ? $this->getMaxUploadSize($mapping['max_size']) : $mapping['max_size'] ; diff --git a/Event/PostChunkUploadEvent.php b/Event/PostChunkUploadEvent.php index 9b32dfd..32e8fe7 100644 --- a/Event/PostChunkUploadEvent.php +++ b/Event/PostChunkUploadEvent.php @@ -8,7 +8,7 @@ use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; class PostChunkUploadEvent extends Event { - protected $file; + protected $chunk; protected $request; protected $type; protected $response; diff --git a/Resources/doc/frontend_plupload.md b/Resources/doc/frontend_plupload.md index deb1ce0..0c2e01d 100644 --- a/Resources/doc/frontend_plupload.md +++ b/Resources/doc/frontend_plupload.md @@ -1,7 +1,7 @@ Use Plupload in your Symfony2 application ========================================= -Download [Plupload](http://http://www.plupload.com/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}`. +Download [Plupload](http://www.plupload.com/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}`. ```html <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> diff --git a/Resources/doc/orphanage.md b/Resources/doc/orphanage.md index 6848615..9e4db06 100644 --- a/Resources/doc/orphanage.md +++ b/Resources/doc/orphanage.md @@ -53,6 +53,18 @@ class AcmeController extends Controller You will get an array containing the moved files. +Note that you can move only one or a set of defined files out of the orphanage by passing an array to $manager->getFiles(). +For instance, you can use this to move a specific file: +```php + // get files + $files = $manager->getFiles(); + + // reduce the scope of the Finder object to what you want + $files->files()->name($filename); + $manager->uploadFiles(iterator_to_array($files)); +``` +In this example, $filename is the name of the file you want to move out of the orphanage. + > If you are using Gaufrette, these files are instances of `Gaufrette\File`, otherwise `SplFileInfo`. ## Configure the Orphanage diff --git a/Resources/meta/LICENSE b/Resources/meta/LICENSE index 44d421f..bebab95 100644 --- a/Resources/meta/LICENSE +++ b/Resources/meta/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013 1up GmbH +Copyright (c) 2015 1up GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php index fad6c0f..cd8c070 100644 --- a/Routing/RouteLoader.php +++ b/Routing/RouteLoader.php @@ -32,14 +32,22 @@ class RouteLoader extends Loader $upload = new Route( sprintf('%s/_uploader/%s/upload', $options['route_prefix'], $type), array('_controller' => $service . ':upload', '_format' => 'json'), - array('_method' => 'POST') + array(), + array(), + '', + array(), + array('POST', 'PUT', 'PATCH') ); if ($options['enable_progress'] === true) { $progress = new Route( sprintf('%s/_uploader/%s/progress', $options['route_prefix'], $type), array('_controller' => $service . ':progress', '_format' => 'json'), - array('_method' => 'POST') + array(), + array(), + '', + array(), + array('POST') ); $routes->add(sprintf('_uploader_progress_%s', $type), $progress); @@ -49,7 +57,11 @@ class RouteLoader extends Loader $progress = new Route( sprintf('%s/_uploader/%s/cancel', $options['route_prefix'], $type), array('_controller' => $service . ':cancel', '_format' => 'json'), - array('_method' => 'POST') + array(), + array(), + '', + array(), + array('POST') ); $routes->add(sprintf('_uploader_cancel_%s', $type), $progress); diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index 9e6d26a..2b0abf7 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -40,8 +40,7 @@ abstract class AbstractControllerTest extends WebTestCase */ public function testCallByGet() { - $endpoint = $this->helper->endpoint($this->getConfigKey()); - $this->client->request('GET', $endpoint); + $this->implTestCallBy('GET'); } /** @@ -49,25 +48,30 @@ abstract class AbstractControllerTest extends WebTestCase */ public function testCallByDelete() { - $endpoint = $this->helper->endpoint($this->getConfigKey()); - $this->client->request('DELETE', $endpoint); + $this->implTestCallBy('DELETE'); } - /** - * @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException - */ - public function testCallByPut() + public function testCallByPatch() { - $endpoint = $this->helper->endpoint($this->getConfigKey()); - $this->client->request('PUT', $endpoint); + $this->implTestCallBy('PATCH'); } public function testCallByPost() + { + $this->implTestCallBy('POST'); + } + + public function testCallByPut() + { + $this->implTestCallBy('PUT'); + } + + protected function implTestCallBy($method) { $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, array(), array(), $this->requestHeaders); + $client->request($method, $endpoint, array(), array(), $this->requestHeaders); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php index 4058039..95b35ab 100644 --- a/Tests/Routing/RouteLoaderTest.php +++ b/Tests/Routing/RouteLoaderTest.php @@ -33,8 +33,8 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase foreach ($routes as $route) { $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); - $this->assertEquals($route->getDefault('_format'), 'json'); - $this->assertEquals($route->getRequirement('_method'), 'POST'); + $this->assertEquals('json', $route->getDefault('_format')); + $this->assertContains('POST', $route->getMethods()); } } @@ -55,8 +55,8 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase foreach ($routes as $route) { $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); - $this->assertEquals($route->getDefault('_format'), 'json'); - $this->assertEquals($route->getRequirement('_method'), 'POST'); + $this->assertEquals('json', $route->getDefault('_format')); + $this->assertContains('POST', $route->getMethods()); $this->assertEquals(0, strpos($route->getPath(), $prefix)); } diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php index c042e56..3cac14d 100644 --- a/Twig/Extension/UploaderExtension.php +++ b/Twig/Extension/UploaderExtension.php @@ -21,11 +21,11 @@ class UploaderExtension extends \Twig_Extension public function getFunctions() { return array( - 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'), - 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'), - 'oneup_uploader_cancel' => new \Twig_Function_Method($this, 'cancel'), - 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey'), - 'oneup_uploader_maxsize' => new \Twig_Function_Method($this, 'maxSize'), + new \Twig_SimpleFunction('oneup_uploader_endpoint', array($this, 'endpoint')), + new \Twig_SimpleFunction('oneup_uploader_progress', array($this, 'progress')), + new \Twig_SimpleFunction('oneup_uploader_cancel', array($this, 'cancel')), + new \Twig_SimpleFunction('oneup_uploader_upload_key', array($this, 'uploadKey')), + new \Twig_SimpleFunction('oneup_uploader_maxsize', array($this, 'maxSize')), ); } diff --git a/Uploader/Chunk/Storage/FilesystemStorage.php b/Uploader/Chunk/Storage/FilesystemStorage.php index 8855188..acc98d7 100644 --- a/Uploader/Chunk/Storage/FilesystemStorage.php +++ b/Uploader/Chunk/Storage/FilesystemStorage.php @@ -56,7 +56,7 @@ class FilesystemStorage implements ChunkStorageInterface throw new \InvalidArgumentException('The first argument must implement \IteratorAggregate interface.'); } - $iterator = $chunks->getIterator()->getInnerIterator(); + $iterator = $chunks->getIterator(); $base = $iterator->current(); $iterator->next(); diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php index 6903db7..9352b4e 100644 --- a/Uploader/Orphanage/OrphanageManager.php +++ b/Uploader/Orphanage/OrphanageManager.php @@ -17,6 +17,11 @@ class OrphanageManager $this->config = $config; } + public function has($key) + { + return $this->container->has(sprintf('oneup_uploader.orphanage.%s', $key)); + } + public function get($key) { return $this->container->get(sprintf('oneup_uploader.orphanage.%s', $key));
0
1b6eb43ee3f5c4d8aa97f94f4a909dd0c74702f4
1up-lab/OneupUploaderBundle
Fixed dead link
commit 1b6eb43ee3f5c4d8aa97f94f4a909dd0c74702f4 Author: David Greminger <[email protected]> Date: Thu Jan 9 16:01:14 2014 +0100 Fixed dead link diff --git a/Resources/doc/index.md b/Resources/doc/index.md index f384284..e9469ad 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -142,7 +142,7 @@ This is absolutely no problem, just follow the instructions given in the corresp > Why didn't you implement the _delete_ feature provided by Fine Uploader? -FineUploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](https://github.com/Widen/fine-uploader/blob/master/docs/options-fineuploaderbasic.md#deletefile-option-properties) and on [the blog](http://blog.fineuploader.com/2013/01/delete-uploaded-file-in-33.html) of Fine Uploader. +FineUploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](http://docs.fineuploader.com/features/delete.html) and on [the blog](http://blog.fineuploader.com/2013/01/delete-uploaded-file-in-33.html) of Fine Uploader. > Why didn't you implement the _delete_ feature provided by another library?
0
f887afd548492ce5596bf75d4e796d3f6a147280
1up-lab/OneupUploaderBundle
Added .idea to gitignore.
commit f887afd548492ce5596bf75d4e796d3f6a147280 Author: Jim Schmid <[email protected]> Date: Fri Jun 20 10:58:58 2014 +0200 Added .idea to gitignore. diff --git a/.gitignore b/.gitignore index 7c766c7..6b0fe35 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ phpunit.xml vendor log Tests/App/cache -Tests/App/logs \ No newline at end of file +Tests/App/logs + +.idea \ No newline at end of file
0
dac856885ff3c980f82c7e3cd70e4cd755f39fe7
1up-lab/OneupUploaderBundle
Removed warning in Readme.
commit dac856885ff3c980f82c7e3cd70e4cd755f39fe7 Author: Jim Schmid <[email protected]> Date: Thu Jul 25 18:08:09 2013 +0200 Removed warning in Readme. diff --git a/README.md b/README.md index cfdfbdb..0df2f93 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,3 @@ -*** - -**Warning**: There is currently a pretty serious issue reported. Until further notice, -consider chunked uploads as *not-working*. It is highly recommended to switch from chunked -uploads to non-chunked uploads until this issue is fixed again. You can find more -information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21). - -*** - - OneupUploaderBundle ===================
0
d0323dafd58175a8f003a892795ad12e716128c8
1up-lab/OneupUploaderBundle
Fixed deprecations and removed symfony/templating (#440) Co-authored-by: MB_GMBH\borisf <[email protected]>
commit d0323dafd58175a8f003a892795ad12e716128c8 Author: knallcharge <[email protected]> Date: Mon Feb 19 13:44:30 2024 +0100 Fixed deprecations and removed symfony/templating (#440) Co-authored-by: MB_GMBH\borisf <[email protected]> diff --git a/composer.json b/composer.json index 8924951..19673e7 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,6 @@ "symfony/finder": "^5.4 || ^6.0 || ^7.0", "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0", "symfony/mime": "^5.4 || ^6.0 || ^7.0", - "symfony/templating": "^5.4 || ^6.0 || ^7.0", "symfony/translation": "^5.4 || ^6.0 || ^7.0", "symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0", "symfony/yaml": "^5.4 || ^6.0 || ^7.0", diff --git a/src/Command/ClearOrphansCommand.php b/src/Command/ClearOrphansCommand.php index 717c59f..ef2f88d 100644 --- a/src/Command/ClearOrphansCommand.php +++ b/src/Command/ClearOrphansCommand.php @@ -15,8 +15,6 @@ use Symfony\Component\Console\Output\OutputInterface; )] class ClearOrphansCommand extends Command { - protected static $defaultName = 'oneup:uploader:clear-orphans'; - /** * @var OrphanageManager */ diff --git a/src/Resources/config/templating.xml b/src/Resources/config/templating.xml index 8a80df7..0ed80fb 100644 --- a/src/Resources/config/templating.xml +++ b/src/Resources/config/templating.xml @@ -9,7 +9,6 @@ <service id="oneup_uploader.templating.uploader_helper" class="Oneup\UploaderBundle\Templating\Helper\UploaderHelper" public="true"> <argument type="service" id="router" /> <argument>%oneup_uploader.maxsize%</argument> - <tag name="templating.helper" alias="oneup_uploader" /> </service> </services> diff --git a/src/Templating/Helper/UploaderHelper.php b/src/Templating/Helper/UploaderHelper.php index 70e89ae..f537817 100644 --- a/src/Templating/Helper/UploaderHelper.php +++ b/src/Templating/Helper/UploaderHelper.php @@ -5,9 +5,8 @@ declare(strict_types=1); namespace Oneup\UploaderBundle\Templating\Helper; use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\Templating\Helper\Helper; -class UploaderHelper extends Helper +class UploaderHelper { public function __construct(protected RouterInterface $router, protected array $maxsize) {
0
f1f84bca6eae7b49f47e43ee21b2bf0a4605e2f8
1up-lab/OneupUploaderBundle
better file size calculation for gaufrette files
commit f1f84bca6eae7b49f47e43ee21b2bf0a4605e2f8 Author: mitom <[email protected]> Date: Thu Oct 10 13:46:35 2013 +0200 better file size calculation for gaufrette files diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1cf8414..c11e014 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -27,6 +27,7 @@ class Configuration implements ConfigurationInterface ->end() ->scalarNode('filesystem')->defaultNull()->end() ->scalarNode('directory')->defaultNull()->end() + ->scalarNode('stream_wrapper')->defaultNull()->end() ->scalarNode('sync_buffer_size')->defaultValue('100K')->end() ->scalarNode('prefix')->defaultValue('chunks')->end() ->end() @@ -68,6 +69,7 @@ class Configuration implements ConfigurationInterface ->end() ->scalarNode('filesystem')->defaultNull()->end() ->scalarNode('directory')->defaultNull()->end() + ->scalarNode('stream_wrapper')->defaultNull()->end() ->scalarNode('sync_buffer_size')->defaultValue('100K')->end() ->end() ->end() diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 6a8bff1..5f5ece9 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -116,7 +116,13 @@ class OneupUploaderExtension extends Extension ->addArgument($config['directory']) ; } else { - $this->registerGaufretteStorage('oneup_uploader.chunks_storage', $storageClass, $config['filesystem'], $config['sync_buffer_size'], $config['prefix']); + $this->registerGaufretteStorage( + 'oneup_uploader.chunks_storage', + $storageClass, $config['filesystem'], + $config['sync_buffer_size'], + $config['stream_wrapper'], + $config['prefix'] + ); // enforce load distribution when using gaufrette as chunk // torage to avoid moving files forth-and-back @@ -150,7 +156,13 @@ class OneupUploaderExtension extends Extension } if ($config['type'] == 'gaufrette') { - $this->registerGaufretteStorage($storageName, $storageClass, $config['filesystem'], $config['sync_buffer_size']); + $this->registerGaufretteStorage( + $storageName, + $storageClass, + $config['filesystem'], + $config['sync_buffer_size'], + $config['stream_wrapper'] + ); } $storageService = new Reference($storageName); @@ -176,7 +188,7 @@ class OneupUploaderExtension extends Extension return $storageService; } - protected function registerGaufretteStorage($key, $class, $filesystem, $buffer, $prefix = '') + protected function registerGaufretteStorage($key, $class, $filesystem, $buffer, $streamWrapper = null, $prefix = '') { if(!class_exists('Gaufrette\\Filesystem')) throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a chunk storage service.'); @@ -188,6 +200,7 @@ class OneupUploaderExtension extends Extension ->register($key, $class) ->addArgument(new Reference($filesystem)) ->addArgument($this->getValueInBytes($buffer)) + ->addArgument($streamWrapper) ->addArgument($prefix) ; } diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php index 00b0031..98707b7 100644 --- a/Uploader/Chunk/Storage/GaufretteStorage.php +++ b/Uploader/Chunk/Storage/GaufretteStorage.php @@ -14,8 +14,9 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface { protected $unhandledChunk; protected $prefix; + protected $streamWrapperPrefix; - public function __construct(Filesystem $filesystem, $bufferSize, $prefix) + public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix, $prefix) { if (!($filesystem->getAdapter() instanceof StreamFactory)) { throw new \InvalidArgumentException('The filesystem used as chunk storage must implement StreamFactory'); @@ -23,6 +24,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface $this->filesystem = $filesystem; $this->bufferSize = $bufferSize; $this->prefix = $prefix; + $this->streamWrapperPrefix = $streamWrapperPrefix; } public function clear($maxAge) @@ -128,7 +130,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface return $uploaded; } - return new GaufretteFile($uploaded, $this->filesystem); + return new GaufretteFile($uploaded, $this->filesystem, $this->streamWrapperPrefix); } public function cleanup($path) diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php index fd0701a..0c73be5 100644 --- a/Uploader/File/GaufretteFile.php +++ b/Uploader/File/GaufretteFile.php @@ -2,17 +2,21 @@ namespace Oneup\UploaderBundle\Uploader\File; +use Gaufrette\Adapter\StreamFactory; use Gaufrette\File; use Gaufrette\Filesystem; class GaufretteFile extends File implements FileInterface { protected $filesystem; + protected $streamWrapperPrefix; + protected $mimeType; - public function __construct(File $file, Filesystem $filesystem) + public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null) { parent::__construct($file->getKey(), $filesystem); $this->filesystem = $filesystem; + $this->streamWrapperPrefix = $streamWrapperPrefix; } /** @@ -20,14 +24,28 @@ class GaufretteFile extends File implements FileInterface * * !! WARNING !! * Calling this loads the entire file into memory, - * in case of bigger files this could throw exceptions, + * unless it is on a stream-capable filesystem. + * In case of bigger files this could throw exceptions, * and will have heavy performance footprint. * !! ------- !! * - * TODO mock/calculate the size if possible and use that instead? */ public function getSize() { + // This can only work on streamable files, so basically local files, + // still only perform it once even on local files to avoid bothering the filesystem.php g + if ($this->filesystem->getAdapter() instanceof StreamFactory && !$this->size) { + if ($this->streamWrapperPrefix) { + try { + $this->setSize(filesize($this->streamWrapperPrefix.$this->getKey())); + } catch (\Exception $e) { + // Fail gracefully if there was a problem with opening the file and + // let gaufrette load the file into memory allowing it to throw exceptions + // if that doesn't work either. + } + } + } + return parent::getSize(); } @@ -51,11 +69,26 @@ class GaufretteFile extends File implements FileInterface */ public function getMimeType() { - $finfo = finfo_open(FILEINFO_MIME_TYPE); + // This can only work on streamable files, so basically local files, + // still only perform it once even on local files to avoid bothering the filesystem. + if ($this->filesystem->getAdapter() instanceof StreamFactory && !$this->mimeType) { + if ($this->streamWrapperPrefix) { + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $this->mimeType = finfo_file($finfo, $this->streamWrapperPrefix.$this->getKey()); + finfo_close($finfo); + } + } - return finfo_file($finfo, $this->getKey()); + return $this->mimeType; } + /** + * Now that we may be able to get the mime-type the extension + * COULD be guessed based on that, but it would be even less + * accurate as mime-types can have multiple extensions + * + * @return mixed + */ public function getExtension() { return pathinfo($this->getKey(), PATHINFO_EXTENSION); diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index c69e3b2..315b92b 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -10,11 +10,13 @@ use Oneup\UploaderBundle\Uploader\Gaufrette\StreamManager; class GaufretteStorage extends StreamManager implements StorageInterface { + protected $streamWrapperPrefix; - public function __construct(Filesystem $filesystem, $bufferSize) + public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix) { $this->filesystem = $filesystem; $this->bufferSize = $bufferSize; + $this->streamWrapperPrefix = $streamWrapperPrefix; } public function upload(FileInterface $file, $name, $path = null) @@ -29,7 +31,7 @@ class GaufretteStorage extends StreamManager implements StorageInterface if ($file->getFilesystem() == $this->filesystem) { $file->getFilesystem()->rename($file->getKey(), $path); - return $this->filesystem->get($path); + return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix); } } @@ -40,7 +42,7 @@ class GaufretteStorage extends StreamManager implements StorageInterface $this->stream($file, $dst); - return $this->filesystem->get($path); + return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix); } }
0
1208fcfcaafab2fe523c267931201138666dc923
1up-lab/OneupUploaderBundle
Removed setScope due to the usage of RequestStack
commit 1208fcfcaafab2fe523c267931201138666dc923 Author: David Greminger <[email protected]> Date: Thu Dec 10 14:21:53 2015 +0100 Removed setScope due to the usage of RequestStack diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index aec580d..7f35224 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -115,7 +115,6 @@ class OneupUploaderExtension extends Extension ->addArgument($key) ->addTag('oneup_uploader.routable', array('type' => $key)) - ->setScope('request') ; return $controllerName;
0
9489808c15c95724362803c9e337adab053ba17f
1up-lab/OneupUploaderBundle
The file bag extractor does no longer return null values. The file bag extractor in AbstractController now checks if a value is null and skips it if so. This is especially usefull for single file uploads using the form component for the field and the controller service for uploading. See #95.
commit 9489808c15c95724362803c9e337adab053ba17f Author: Jim Schmid <[email protected]> Date: Wed Mar 26 08:15:19 2014 +0100 The file bag extractor does no longer return null values. The file bag extractor in AbstractController now checks if a value is null and skips it if so. This is especially usefull for single file uploads using the form component for the field and the controller service for uploading. See #95. diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index fd78592..a551ba8 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -83,7 +83,7 @@ abstract class AbstractController $fileIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($fileBag), \RecursiveIteratorIterator::SELF_FIRST); foreach ($fileIterator as $file) { - if (is_array($file)) { + if (is_array($file) || null === $file) { continue; } diff --git a/Tests/Controller/FileBagExtractorTest.php b/Tests/Controller/FileBagExtractorTest.php new file mode 100644 index 0000000..e757ebb --- /dev/null +++ b/Tests/Controller/FileBagExtractorTest.php @@ -0,0 +1,102 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Controller; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\FileBag; + +class FileBagExtractorText extends \PHPUnit_Framework_TestCase +{ + protected $method; + protected $mock; + + public function setUp() + { + $controller = 'Oneup\UploaderBundle\Controller\AbstractController'; + $mock = $this->getMockBuilder($controller) + ->disableOriginalConstructor() + ->getMock() + ; + + $method = new \ReflectionMethod($controller, 'getFiles'); + $method->setAccessible(true); + + $this->method = $method; + $this->mock = $mock; + } + + public function testEmpty() + { + $result = $this->invoke(new FileBag()); + + $this->assertInternalType('array', $result); + $this->assertEmpty($result); + } + + public function testWithNullArrayValue() + { + $bag = new FileBag(array( + array(null) + )); + + $result = $this->invoke($bag); + + $this->assertInternalType('array', $result); + $this->assertEmpty($result); + } + + public function testWithSingleFile() + { + $bag = new FileBag(array( + new UploadedFile(__FILE__, 'name') + )); + + $result = $this->invoke($bag); + + $this->assertInternalType('array', $result); + $this->assertNotEmpty($result); + $this->assertCount(1, $result); + } + + public function testWithMultipleFiles() + { + $bag = new FileBag(array( + new UploadedFile(__FILE__, 'name1'), + new UploadedFile(__FILE__, 'name2'), + new UploadedFile(__FILE__, 'name3') + )); + + $result = $this->invoke($bag); + + $this->assertInternalType('array', $result); + $this->assertNotEmpty($result); + $this->assertCount(3, $result); + } + + public function testWithMultipleFilesContainingNullValues() + { + $bag = new FileBag(array( + // we need to inject an array, + // otherwise the FileBag will type check against + // UploadedFile resulting in an InvalidArgumentException. + array( + new UploadedFile(__FILE__, 'name1'), + null, + new UploadedFile(__FILE__, 'name2'), + null, + new UploadedFile(__FILE__, 'name3') + ) + )); + + $result = $this->invoke($bag); + + $this->assertInternalType('array', $result); + $this->assertNotEmpty($result); + $this->assertCount(3, $result); + } + + protected function invoke(FileBag $bag) + { + return $this->method->invoke($this->mock, $bag); + } +}
0
706cb283b790498efc22f67c4cd3deb31237b245
1up-lab/OneupUploaderBundle
Revert "Added Upgrade Note for 1.0" Hope I got the correct hash this time. Sorry for the history mess. This reverts commit ec662ba25f61230854d6fbbd4706e503a1674c9e.
commit 706cb283b790498efc22f67c4cd3deb31237b245 Author: Jim Schmid <[email protected]> Date: Wed Oct 23 15:31:12 2013 +0200 Revert "Added Upgrade Note for 1.0" Hope I got the correct hash this time. Sorry for the history mess. This reverts commit ec662ba25f61230854d6fbbd4706e503a1674c9e. diff --git a/README.md b/README.md index 0abe5c1..a8b708b 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- -* Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57). * If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320). * Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md). * Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_logic.md#using-chunked-uploads).
0
b1b00b3d69f94e8d895c2245385fe7cc8a3c1bbf
1up-lab/OneupUploaderBundle
Dispatch generic events using the mapping key in the event name.
commit b1b00b3d69f94e8d895c2245385fe7cc8a3c1bbf Author: Jim Schmid <[email protected]> Date: Thu Apr 18 19:01:20 2013 +0200 Dispatch generic events using the mapping key in the event name. diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 07836d0..75e1cc8 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -50,15 +50,19 @@ abstract class AbstractController { $dispatcher = $this->container->get('event_dispatcher'); - // dispatch post upload event + // dispatch post upload event (both the specific and the general) $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); + $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postUploadEvent); + + var_dump(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type)); if(!$this->config['use_orphanage']) { - // dispatch post persist event + // dispatch post persist event (both the specific and the general) $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); + $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postPersistEvent); } } @@ -81,4 +85,4 @@ abstract class AbstractController throw new UploadException('error.blacklist'); } -} \ No newline at end of file +} diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md index 1163dee..dcb0343 100644 --- a/Resources/doc/custom_logic.md +++ b/Resources/doc/custom_logic.md @@ -6,6 +6,8 @@ In almost every use case you need to further process uploaded files. For example * `PostUploadEvent`: Will be dispatched after a file has been uploaded and moved. * `PostPersistEvent`: The same as `PostUploadEvent` but will only be dispatched if no `Orphanage` is used. +> You'll find more information on this topic in the [Event documentation](events.md) + To listen to one of these events you need to create an `EventListener`. ```php diff --git a/Resources/doc/events.md b/Resources/doc/events.md new file mode 100644 index 0000000..30244f2 --- /dev/null +++ b/Resources/doc/events.md @@ -0,0 +1,17 @@ +OneupUploaderBundle Events +========================== + +For a list of general Events, you can always have a look at the `UploadEvents.php` file in the root of this bundle. + +* `oneup_uploader.post_upload` Will be dispatched after a file has been uploaded and moved. +* `oneup_uploader.post_persist` The same as `oneup_uploader.post_upload` but will only be dispatched if no `Orphanage` is used. + +Moreover this bundles also dispatches some special kind of generic events you can listen to. + +* `oneup_uploader.post_upload.{mapping}` +* `oneup_uploader.post_persist.{mapping}` + +The `{mapping}` part is the key of your configured mapping. The examples in this documentation always uses the mapping key `gallery`. So the dispatched event would be called `oneup_uploader.post_upload.gallery`. +Using these generic events can save you some time and coding lines, as you don't have to check for the correct type in the `EventListener`. + +See the [custom_logic.md](custom logic section) of this documentation for specific examples on how to use these Events. \ No newline at end of file diff --git a/Resources/doc/index.md b/Resources/doc/index.md index a8fe6f9..00bc4ae 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -120,6 +120,7 @@ some more advanced features. * [Include your own Namer](custom_namer.md) * [Testing this bundle](testing.md) * [Support a custom uploader](custom_uploader.md) +* [General/Generic Events](events.md) * [Configuration Reference](configuration_reference.md) ## FAQ
0
a658021322e2ed9360f63a4e219d48551c444a21
1up-lab/OneupUploaderBundle
Fix typo
commit a658021322e2ed9360f63a4e219d48551c444a21 Author: David Greminger <[email protected]> Date: Wed Jul 20 14:22:01 2022 +0200 Fix typo diff --git a/README.md b/README.md index daa56ae..c59bc59 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ The entry point of the documentation can be found in the file `docs/index.md` Upgrade Notes ------------- -* Version **4.0.0* supports now [Flysystem 2 & 3](https://github.com/1up-lab/OneupFlysystemBundle) (kudos to @[m2mtech](https://github.com/m2mtech)), see [#412](https://github.com/1up-lab/OneupUploaderBundle/pull/412)! Flysystem 1 and OneupFlysystemBundle < 4.0 support was dropped. +* Version **4.0.0** supports now [Flysystem 2 & 3](https://github.com/1up-lab/OneupFlysystemBundle) (kudos to @[m2mtech](https://github.com/m2mtech)), see [#412](https://github.com/1up-lab/OneupUploaderBundle/pull/412)! Flysystem 1 and OneupFlysystemBundle < 4.0 support was dropped. * Version **3.2.0** supports now Symfony 6 (kudos to @[pich](https://github.com/pich)), see [#421](https://github.com/1up-lab/OneupUploaderBundle/pull/421)! PHP 7.2/7.3 support was dropped. * Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter](https://github.com/steveWinter), @[gubler](https://github.com/gubler), @[patrickbussmann](https://github.com/patrickbussmann), @[ErnadoO](https://github.com/ErnadoO) and @[enumag](https://github.com/enumag), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped. * Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure a file extension validation whitelist now (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262)).
0
79e77c40b446ca1eb6aa768bc7a11db514475dd8
1up-lab/OneupUploaderBundle
Added a test to check the PHP version if you want to use the progress/cancelation feature.
commit 79e77c40b446ca1eb6aa768bc7a11db514475dd8 Author: Jim Schmid <[email protected]> Date: Tue Jun 25 17:34:15 2013 +0200 Added a test to check the PHP version if you want to use the progress/cancelation feature. diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index ca6684a..d1435fa 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -129,6 +129,12 @@ class OneupUploaderExtension extends Extension ->setScope('request') ; + if($mapping['enable_progress'] || $mapping['enable_cancelation']) { + if(strnatcmp(phpversion(), '5.4.0') < 0) { + throw new InvalidArgumentException('You need to run PHP version 5.4.0 or above to use the progress/cancelation feature.'); + } + } + $controllers[$key] = array($controllerName, array( 'enable_progress' => $mapping['enable_progress'], 'enable_cancelation' => $mapping['enable_cancelation']
0
a5824f08728386589bdde272653fb9dd45145a4a
1up-lab/OneupUploaderBundle
Fixed MooUploadController so that chunked uploads work for now.
commit a5824f08728386589bdde272653fb9dd45145a4a Author: Jim Schmid <[email protected]> Date: Fri Apr 12 14:15:47 2013 +0200 Fixed MooUploadController so that chunked uploads work for now. diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php index fcd2435..949663d 100644 --- a/Controller/MooUploadController.php +++ b/Controller/MooUploadController.php @@ -50,7 +50,7 @@ class MooUploadController extends AbstractChunkedController $response = $this->response; $response->setId($headers->get('x-file-id')); - $response->setSize($headers->get('x-file-size')); + $response->setSize($headers->get('content-length')); $response->setName($headers->get('x-file-name')); $response->setUploadedName($uploadFileName); @@ -108,13 +108,13 @@ class MooUploadController extends AbstractChunkedController protected function createIndex($id) { - $ints = ''; + $ints = 0; // loop through every char and convert it to an integer // we need this for sorting foreach(str_split($id) as $char) { - $ints .= ord($char); + $ints += ord($char); } return $ints;
0
24744bbf3cd937439031013a0aa13668ecb547d4
1up-lab/OneupUploaderBundle
Modified test matrix
commit 24744bbf3cd937439031013a0aa13668ecb547d4 Author: David Greminger <[email protected]> Date: Thu Dec 10 15:01:24 2015 +0100 Modified test matrix diff --git a/.travis.yml b/.travis.yml index 83d8577..097154d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,13 @@ php: - hhvm env: + - SYMFONY_VERSION=2.4.* + - SYMFONY_VERSION=2.5.* + - SYMFONY_VERSION=2.6.* - SYMFONY_VERSION=2.7.* - SYMFONY_VERSION=2.8.* + - SYMFONY_VERSION=3.0.* + - SYMFONY_VERSION=dev-master cache: directories: @@ -22,22 +27,6 @@ matrix: - php: 7.0 - env: SYMFONY_VERSION=dev-master - include: - - php: 5.6 - env: SYMFONY_VERSION=2.4.* - - php: 5.6 - env: SYMFONY_VERSION=2.5.* - - php: 5.6 - env: SYMFONY_VERSION=2.6.* - - php: 5.6 - env: SYMFONY_VERSION=2.7.* - - php: 5.6 - env: SYMFONY_VERSION=2.8.* - - php: 5.6 - env: SYMFONY_VERSION=3.0.* - - php: 5.6 - env: SYMFONY_VERSION=dev-master - before_script: - composer selfupdate - composer require symfony/http-kernel:${SYMFONY_VERSION} --prefer-source
0
f5b496f44c9fcdaeb9cca2866981969f121e73cd
1up-lab/OneupUploaderBundle
Deprecation removal Symfony 4.2 (#357) ContainerAwareCommand is deprecated since Symfony 4.2. I just replaced it by Command service and then use dependency injection in command controller to make use of ChunkManager or OrphanageManager instead of getting it by container get method. Fix #354
commit f5b496f44c9fcdaeb9cca2866981969f121e73cd Author: Wait4Code <[email protected]> Date: Fri Apr 5 09:57:01 2019 +0200 Deprecation removal Symfony 4.2 (#357) ContainerAwareCommand is deprecated since Symfony 4.2. I just replaced it by Command service and then use dependency injection in command controller to make use of ChunkManager or OrphanageManager instead of getting it by container get method. Fix #354 diff --git a/Command/ClearChunkCommand.php b/Command/ClearChunkCommand.php index b72bd93..df2b388 100644 --- a/Command/ClearChunkCommand.php +++ b/Command/ClearChunkCommand.php @@ -2,14 +2,24 @@ namespace Oneup\UploaderBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ClearChunkCommand extends ContainerAwareCommand +class ClearChunkCommand extends Command { protected static $defaultName = 'oneup:uploader:clear-chunks'; // Make command lazy load + /** @var ChunkManager */ + protected $manager; + + public function __construct(ChunkManager $manager, ?string $name = null) + { + parent::__construct($name); + $this->manager = $manager; + } + protected function configure() { $this @@ -20,7 +30,6 @@ class ClearChunkCommand extends ContainerAwareCommand protected function execute(InputInterface $input, OutputInterface $output) { - $manager = $this->getContainer()->get('oneup_uploader.chunk_manager'); $manager->clear(); } } diff --git a/Command/ClearOrphansCommand.php b/Command/ClearOrphansCommand.php index a2d44e7..34eff28 100644 --- a/Command/ClearOrphansCommand.php +++ b/Command/ClearOrphansCommand.php @@ -2,14 +2,24 @@ namespace Oneup\UploaderBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ClearOrphansCommand extends ContainerAwareCommand +class ClearOrphansCommand extends Command { protected static $defaultName = 'oneup:uploader:clear-orphans'; // Make command lazy load + /** @var OrphanageManager */ + protected $manager; + + public function __construct(OrphanageManager $manager, ?string $name = null) + { + parent::__construct($name); + $this->manager = $manager; + } + protected function configure() { $this @@ -20,7 +30,6 @@ class ClearOrphansCommand extends ContainerAwareCommand protected function execute(InputInterface $input, OutputInterface $output) { - $manager = $this->getContainer()->get('oneup_uploader.orphanage_manager'); $manager->clear(); } }
0
545274acc30b688b4ad69346b822ad9c79ffd667
1up-lab/OneupUploaderBundle
Fixed wrong version constraint for symfony/framework-bundle
commit 545274acc30b688b4ad69346b822ad9c79ffd667 Author: David Greminger <[email protected]> Date: Thu Dec 10 15:39:40 2015 +0100 Fixed wrong version constraint for symfony/framework-bundle diff --git a/composer.json b/composer.json index 3d765c4..e9f912f 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { - "symfony/framework-bundle": "2.4.*", + "symfony/framework-bundle": "^2.4.0|~3.0", "symfony/http-kernel": "^2.4.0|~3.0", "symfony/finder": "^2.4.0|~3.0" },
0
568dfb13740c22de13205a702eb4b510cab0159f
1up-lab/OneupUploaderBundle
Merge pull request #194 from a-tawila/master replace the deprecated "Twig_Function_Method"
commit 568dfb13740c22de13205a702eb4b510cab0159f (from db6423ba0afb99615c265112ef4075ef75164faa) Merge: db6423b 0f30d96 Author: David Greminger <[email protected]> Date: Wed Oct 28 09:11:12 2015 +0100 Merge pull request #194 from a-tawila/master replace the deprecated "Twig_Function_Method" diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php index c042e56..3cac14d 100644 --- a/Twig/Extension/UploaderExtension.php +++ b/Twig/Extension/UploaderExtension.php @@ -21,11 +21,11 @@ class UploaderExtension extends \Twig_Extension public function getFunctions() { return array( - 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'), - 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'), - 'oneup_uploader_cancel' => new \Twig_Function_Method($this, 'cancel'), - 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey'), - 'oneup_uploader_maxsize' => new \Twig_Function_Method($this, 'maxSize'), + new \Twig_SimpleFunction('oneup_uploader_endpoint', array($this, 'endpoint')), + new \Twig_SimpleFunction('oneup_uploader_progress', array($this, 'progress')), + new \Twig_SimpleFunction('oneup_uploader_cancel', array($this, 'cancel')), + new \Twig_SimpleFunction('oneup_uploader_upload_key', array($this, 'uploadKey')), + new \Twig_SimpleFunction('oneup_uploader_maxsize', array($this, 'maxSize')), ); }
0
8172cea52f0daf23cf30be17fc657cae9cd99914
1up-lab/OneupUploaderBundle
Moved UploaderController to specific FineUploaderController
commit 8172cea52f0daf23cf30be17fc657cae9cd99914 Author: Jim Schmid <[email protected]> Date: Tue Apr 9 20:57:50 2013 +0200 Moved UploaderController to specific FineUploaderController diff --git a/Controller/UploaderController.php b/Controller/FineUploaderController.php similarity index 98% rename from Controller/UploaderController.php rename to Controller/FineUploaderController.php index 3bf61a5..35996c0 100644 --- a/Controller/UploaderController.php +++ b/Controller/FineUploaderController.php @@ -14,7 +14,7 @@ use Oneup\UploaderBundle\Controller\UploadControllerInterface; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; -class UploaderController implements UploadControllerInterface +class FineUploaderController implements UploadControllerInterface { protected $container; protected $storage;
0
e2dbf8079c5ed044f0108bfd382879fff06b7dd9
1up-lab/OneupUploaderBundle
Fix links in README.md (#409)
commit e2dbf8079c5ed044f0108bfd382879fff06b7dd9 Author: tomasz-kusy <[email protected]> Date: Tue Aug 3 13:37:48 2021 +0200 Fix links in README.md (#409) diff --git a/README.md b/README.md index b717f2b..4b177c6 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ OneupUploaderBundle [![CI](https://github.com/1up-lab/OneupUploaderBundle/workflows/CI/badge.svg)](https://github.com/1up-lab/OneupUploaderBundle/actions) [![Total Downloads](https://poser.pugx.org/oneup/uploader-bundle/d/total.png)](https://packagist.org/packages/oneup/uploader-bundle) -The OneupUploaderBundle for Symfony adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md). +The OneupUploaderBundle for Symfony adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_uploader.md). * [Dropzone](http://www.dropzonejs.com/) * [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/) @@ -28,7 +28,7 @@ Features included: Documentation ------------- -The entry point of the documentation can be found in the file `Resources/docs/index.md` +The entry point of the documentation can be found in the file `docs/index.md` [Read the documentation for master](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/index.md) @@ -39,8 +39,8 @@ Upgrade Notes * Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). * Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57). * If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320). -* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md). -* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_logic.md#using-chunked-uploads). +* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_error_handler.md). +* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_logic.md#using-chunked-uploads). * Event names [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be) in Version **0.9.3**, update your EventListener accordingly. License
0
d7e7cc54ccd005dae566ddb15487e2d896bc377d
1up-lab/OneupUploaderBundle
Fixed a typo.
commit d7e7cc54ccd005dae566ddb15487e2d896bc377d Author: Jim Schmid <[email protected]> Date: Tue Apr 9 11:10:31 2013 +0200 Fixed a typo. diff --git a/Resources/doc/index.md b/Resources/doc/index.md index bceea87..d6c9855 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -18,7 +18,7 @@ framework: ## Installation -Perform the following step to install and use the basic functionality of the OneupUploaderBundle: +Perform the following steps to install and use the basic functionality of the OneupUploaderBundle: * Download OnueupUploaderBundle using Composer * Enable the bundle
0
88dad9435f0a92e9aa9ef9f0fd9957d22030d394
1up-lab/OneupUploaderBundle
Fixes uploadFiles on Orphanage and added an OrphanageManager to retrieve the typed orphanage from container.
commit 88dad9435f0a92e9aa9ef9f0fd9957d22030d394 Author: Jim Schmid <[email protected]> Date: Thu Mar 28 17:26:47 2013 +0100 Fixes uploadFiles on Orphanage and added an OrphanageManager to retrieve the typed orphanage from container. diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index b1768df..97bb48f 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -26,6 +26,17 @@ class OneupUploaderExtension extends Extension $config['chunks']['directory'] = sprintf('%s/uploader/chunks', $container->getParameter('kernel.cache_dir')); } + if(!array_key_exists('domain', $config['orphanage'])) + { + $tmpArr = explode('.', $config['orphanage']['filesystem']); + $tmpArr = explode('_', end($tmpArr)); + + $domain = reset($tmpArr); + + $config['orphanage']['domain'] = $domain; + } + + $container->setParameter('oneup_uploader.chunks', $config['chunks']); $container->setParameter('oneup_uploader.orphanage', $config['orphanage']); diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index b74071a..e5bfa70 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -10,13 +10,20 @@ <parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter> <parameter key="oneup_uploader.storage.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter> <parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Storage\OrphanageStorage</parameter> + <parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter> </parameters> <services> + + <!-- managers --> <service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%"> <argument>%oneup_uploader.chunks%</argument> </service> + <service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%"> + <argument type="service" id="service_container" /> + </service> + <!-- namer --> <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" /> diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php new file mode 100644 index 0000000..9381aa6 --- /dev/null +++ b/Uploader/Orphanage/OrphanageManager.php @@ -0,0 +1,18 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Orphanage; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +class OrphanageManager +{ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + public function get($key) + { + return $this->container->get(sprintf('oneup_uploader.orphanage.%s', $key)); + } +} \ No newline at end of file diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php index 096af12..3d9fae7 100644 --- a/Uploader/Storage/OrphanageStorage.php +++ b/Uploader/Storage/OrphanageStorage.php @@ -4,8 +4,6 @@ namespace Oneup\UploaderBundle\Uploader\Storage; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\File\File; -use Symfony\Component\Finder\Finder; -use Symfony\Component\Filesystem\Filesystem; use Gaufrette\Filesystem as GaufretteFilesystem; use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage; @@ -13,6 +11,7 @@ use Oneup\UploaderBundle\Uploader\Storage\OrphanageStorageInterface; class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInterface { + protected $orphanage; protected $masked; protected $session; protected $config; @@ -22,6 +21,7 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter { parent::__construct($orphanage); + $this->orphanage = $orphanage; $this->masked = $filesystem; $this->session = $session; $this->config = $config; @@ -41,36 +41,40 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter public function uploadFiles($keep = false) { - $system = new Filesystem(); - $finder = new Finder(); - // switch orphanage with masked filesystem $this->filesystem = $this->masked; - if(!$system->exists($this->getPath())) - return array(); - - $finder->in($this->getPath())->files(); - $uploaded = array(); - foreach($finder as $file) + foreach($this->getFiles() as $file) { - $uploaded[] = $this->upload(new UploadedFile($file->getPathname(), $file->getBasename(), null, null, null, true)); + $uploaded[] = parent::upload(new File($this->getWrapper($file)), str_replace($this->getPath(), '', $file)); if(!$keep) { - $system->remove($file); + $this->orphanage->delete($file); } } return $uploaded; } + public function getFiles() + { + $keys = $this->orphanage->listKeys($this->getPath()); + + return $keys['keys']; + } + protected function getPath() { $id = $this->session->getId(); - $path = sprintf('%s/%s', $this->config['directory'], $id); + $path = sprintf('%s/%s/%s', $this->config['directory'], $id, $this->type); return $path; } + + protected function getWrapper($key) + { + return sprintf('gaufrette://%s/%s', $this->config['domain'], $key); + } } \ No newline at end of file
0
4a72ed5e59318774682ffce80012b15e034cb794
1up-lab/OneupUploaderBundle
Update custom_error_handler.md
commit 4a72ed5e59318774682ffce80012b15e034cb794 Author: maurotdo <[email protected]> Date: Thu Aug 8 11:31:10 2013 +0200 Update custom_error_handler.md diff --git a/Resources/doc/custom_error_handler.md b/Resources/doc/custom_error_handler.md index baf4507..b6cd21c 100644 --- a/Resources/doc/custom_error_handler.md +++ b/Resources/doc/custom_error_handler.md @@ -18,7 +18,7 @@ class CustomErrorHandler implements ErrorHandlerInterface { public function addException(ResponseInterface $response, UploadException $exception) { - $message = $exception->getErrorMessage(); + $message = $exception->getMessage(); $response['error'] = $message; } } @@ -42,4 +42,4 @@ oneup_uploader: error_handler: acme_demo.custom_error_handler ``` -**Note**: As of [9dbd905](https://github.com/1up-lab/OneupUploaderBundle/commit/9dbd9056dfe403ce6f1273d2d75fe814d517731a) only the `BlueimpErrorHandler` is implemented. If you know how to implement the error handlers for the other supported frontends, please create a pull request or drop me a note. \ No newline at end of file +**Note**: As of [9dbd905](https://github.com/1up-lab/OneupUploaderBundle/commit/9dbd9056dfe403ce6f1273d2d75fe814d517731a) only the `BlueimpErrorHandler` is implemented. If you know how to implement the error handlers for the other supported frontends, please create a pull request or drop me a note.
0
75ad4626e2556fe78360d840282dc945a08b12d1
1up-lab/OneupUploaderBundle
Added the possibility to configure the frontend.
commit 75ad4626e2556fe78360d840282dc945a08b12d1 Author: Jim Schmid <[email protected]> Date: Tue Apr 9 20:55:50 2013 +0200 Added the possibility to configure the frontend. diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5f061b0..0ae1d2e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -34,6 +34,10 @@ class Configuration implements ConfigurationInterface ->requiresAtLeastOneElement() ->prototype('array') ->children() + ->enumNode('frontend') + ->values(array('fineuploader', 'reserved')) + ->defaultValue('fineuploader') + ->end() ->arrayNode('storage') ->addDefaultsIfNotSet() ->children() diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 04eb240..365063d 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -105,6 +105,7 @@ class OneupUploaderExtension extends Extension } $controllerName = sprintf('oneup_uploader.controller.%s', $key); + $controllerType = sprintf('oneup_uploader.controller.%s.class', $mapping['frontend']) // create controllers based on mapping $container
0
83371099464ab15eb9988a82b5012bec2341dade
1up-lab/OneupUploaderBundle
Refactored controller test environment.
commit 83371099464ab15eb9988a82b5012bec2341dade Author: Jim Schmid <[email protected]> Date: Sat May 4 10:20:14 2013 +0200 Refactored controller test environment. diff --git a/.gitignore b/.gitignore index 820d851..7c766c7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ composer.lock phpunit.xml vendor log +Tests/App/cache +Tests/App/logs \ No newline at end of file diff --git a/Tests/App/AppKernel.php b/Tests/App/AppKernel.php new file mode 100644 index 0000000..2e39ab8 --- /dev/null +++ b/Tests/App/AppKernel.php @@ -0,0 +1,28 @@ +<?php + +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Config\Loader\LoaderInterface; + +class AppKernel extends Kernel +{ + public function registerBundles() + { + $bundles = array( + new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new Symfony\Bundle\SecurityBundle\SecurityBundle(), + new Symfony\Bundle\MonologBundle\MonologBundle(), + new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + new JMS\SerializerBundle\JMSSerializerBundle($this), + + // bundle to test + new Oneup\UploaderBundle\OneupUploaderBundle(), + ); + + return $bundles; + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(__DIR__.'/config/config.yml'); + } +} diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml new file mode 100644 index 0000000..d61f898 --- /dev/null +++ b/Tests/App/config/config.yml @@ -0,0 +1,33 @@ +framework: + #esi: ~ + translator: { fallback: en } + secret: secret + router: + resource: "%kernel.root_dir%/config/routing.yml" + strict_requirements: %kernel.debug% + form: ~ + csrf_protection: ~ + validation: { enable_annotations: true } + templating: + engines: ['php'] + #assets_version: SomeVersionScheme + default_locale: en + trusted_proxies: ~ + session: ~ + fragments: ~ + test: ~ + +monolog: + handlers: + main: + type: fingers_crossed + action_level: error + handler: nested + nested: + type: stream + path: %kernel.logs_dir%/%kernel.environment%.log + level: debug + +oneup_uploader: + mappings: + gallery: ~ \ No newline at end of file diff --git a/Tests/App/config/routing.yml b/Tests/App/config/routing.yml new file mode 100644 index 0000000..71cd825 --- /dev/null +++ b/Tests/App/config/routing.yml @@ -0,0 +1,3 @@ +oneup_uploader: + resource: . + type: uploader \ No newline at end of file diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 1f4f67c..5b67409 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,8 +1,22 @@ <?php -$file = __DIR__.'/../vendor/autoload.php'; -if (!file_exists($file)) { - throw new RuntimeException('Install dependencies to run test suite.'); +$loader = @include __DIR__ . '/../vendor/autoload.php'; +if (!$loader) { + die(<<<'EOT' +You must set up the project dependencies, run the following commands: +wget http://getcomposer.org/composer.phar +php composer.phar install +EOT + ); } -$autoload = require_once $file; \ No newline at end of file +spl_autoload_register(function($class) { + if (0 === strpos($class, 'Oneup\\UploaderBundle\\')) { + $path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php'; + if (!stream_resolve_include_path($path)) { + return false; + } + require_once $path; + return true; + } +}); diff --git a/composer.json b/composer.json index b312ae5..6142788 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,16 @@ }, "require-dev": { - "knplabs/gaufrette": "0.2.*@dev" + "knplabs/gaufrette": "0.2.*@dev", + "symfony/class-loader": "dev-master", + "symfony/security-bundle": "dev-master", + "symfony/monolog-bundle": "dev-master", + "sensio/framework-extra-bundle": "dev-master", + "jms/serializer-bundle": "dev-master", + "symfony/yaml": "dev-master", + "symfony/form": "2.*", + "symfony/twig-bundle": "dev-master", + "symfony/browser-kit": "dev-master" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f3c7e3e..07c869d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="./Tests/bootstrap.php" colors="true"> - + <php> + <server name="KERNEL_DIR" value="Tests/App" /> + </php> + <testsuites> <testsuite name="OneupUploaderBundle test suite"> <directory suffix="Test.php">./Tests</directory>
0
8d3bd1b7e335473aae0e384d403e1c4544eb649a
1up-lab/OneupUploaderBundle
Made this bundle work for Symfony2.3
commit 8d3bd1b7e335473aae0e384d403e1c4544eb649a Author: Jim Schmid <[email protected]> Date: Tue Jun 4 10:01:15 2013 +0200 Made this bundle work for Symfony2.3 diff --git a/composer.json b/composer.json index 5a86478..ac41496 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "symfony/framework-bundle": "2.*", - "symfony/finder": ">=2.0.16,<2.3-dev" + "symfony/finder": ">=2.0.16,<2.4-dev" }, "require-dev": {
0
46acc7713db576a7d5a44b2bc69c4197ae196ae0
1up-lab/OneupUploaderBundle
Merge branch 'really-uniquenamer' of https://github.com/lsv/OneupUploaderBundle into lsv-really-uniquenamer
commit 46acc7713db576a7d5a44b2bc69c4197ae196ae0 (from a453078f0ffc3496f482e39149768fbd1de63823) Merge: a453078 8b6c03e Author: David Greminger <[email protected]> Date: Fri Sep 15 16:34:54 2017 +0200 Merge branch 'really-uniquenamer' of https://github.com/lsv/OneupUploaderBundle into lsv-really-uniquenamer diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 13d8f30..4389640 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -8,6 +8,7 @@ <parameter key="oneup_uploader.chunks_storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\GaufretteStorage</parameter> <parameter key="oneup_uploader.chunks_storage.flysystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage</parameter> <parameter key="oneup_uploader.chunks_storage.filesystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage</parameter> + <parameter key="oneup_uploader.namer.urlsafename.class">Oneup\UploaderBundle\Uploader\Naming\UrlSafeNamer</parameter> <parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter> <parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter> <parameter key="oneup_uploader.storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter> @@ -40,6 +41,7 @@ <!-- namer --> <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" /> + <service id="oneup_uploader.namer.urlsafe" class="%oneup_uploader.namer.urlsafename.class%" /> <!-- routing --> <service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%"> diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md index fea6ee0..37be120 100644 --- a/Resources/doc/custom_namer.md +++ b/Resources/doc/custom_namer.md @@ -1,7 +1,24 @@ Custom Namer ============ -The purpose of a namer service is to name an uploaded file before it is stored to the storage layer. Currently the OneupUploaderBundle only provides a single namer service called `UniqidNamer`, which will return a system wide unique filename using the `uniqid()` function. +The purpose of a namer service is to name an uploaded file before it is stored to the storage layer. + +Currently the OneupUploaderBundle provides two namer methods. +- Default used is a namer called `UniqidNamer`, which will return a system wide unique filename using the `uniqid()` function. +- The other method called `UrlSafeNamer` using `random_bytes` function, see [Using UrlSafeNamer](#urlsafenamer) how to use it + +## UrlSafeNamer + +To enable UrlSafeNamer you will need to change your namer in your mappings to `oneup_uploader.namer.urlsafe` + +Example + +```yml +oneup_uploader: + mappings: + gallery: + namer: oneup_uploader.namer.urlsafe +``` ## Use a custom namer diff --git a/Tests/Uploader/Naming/UrlSafeNamerTest.php b/Tests/Uploader/Naming/UrlSafeNamerTest.php new file mode 100644 index 0000000..1707940 --- /dev/null +++ b/Tests/Uploader/Naming/UrlSafeNamerTest.php @@ -0,0 +1,53 @@ +<?php +namespace Oneup\UploaderBundle\Tests\Uploader\Naming; + +use Oneup\UploaderBundle\Tests\Uploader\File\FileTest; +use Oneup\UploaderBundle\Uploader\File\FilesystemFile; +use Oneup\UploaderBundle\Uploader\Naming\UrlSafeNamer; +use Symfony\Component\HttpFoundation\File\UploadedFile; + +class UrlSafeNamerTest extends FileTest +{ + + public function setUp() + { + $this->path = sys_get_temp_dir(). '/oneup_namer_test'; + mkdir($this->path); + + $this->basename = 'test_file.txt'; + $this->pathname = $this->path .'/'. $this->basename; + $this->extension = 'txt'; + $this->size = 9; //something = 9 bytes + $this->mimeType = 'text/plain'; + + file_put_contents($this->pathname, 'something'); + + $this->file = new FilesystemFile(new UploadedFile($this->pathname, 'test_file.txt', null, null, null, true)); + } + + public function testCanGetString() + { + $namer = new UrlSafeNamer(); + $this->assertTrue(is_string($namer->name($this->file))); + $this->assertStringEndsWith($this->extension, $namer->name($this->file)); + } + + public function test_two_file_names_not_equal() + { + $namer = new UrlSafeNamer(); + // Trying 200 times just to be sure + for($i = 0; $i < 200; $i++) { + $name1 = $namer->name($this->file); + $name2 = $namer->name($this->file); + $this->assertNotEquals($name1, $name2); + } + + } + + public function tearDown() + { + unlink($this->pathname); + rmdir($this->path); + } + +} diff --git a/Uploader/Naming/UrlSafeNamer.php b/Uploader/Naming/UrlSafeNamer.php new file mode 100644 index 0000000..7ff6660 --- /dev/null +++ b/Uploader/Naming/UrlSafeNamer.php @@ -0,0 +1,21 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Naming; + +use Oneup\UploaderBundle\Uploader\File\FileInterface; + +class UrlSafeNamer implements NamerInterface +{ + + /** + * Name a given file and return the name + * + * @param FileInterface $file + * @return string + */ + public function name(FileInterface $file) + { + $bytes = random_bytes(256 / 8); + return rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=') . '.' . $file->getExtension(); + } +} diff --git a/composer.json b/composer.json index b0ef8ce..a5cea42 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "require": { "php":">=5.4", "symfony/framework-bundle": "^2.4.0|~3.0", - "symfony/finder": "^2.4.0|~3.0" + "symfony/finder": "^2.4.0|~3.0", + "paragonie/random_compat": "^1.1" }, "require-dev": { commit 46acc7713db576a7d5a44b2bc69c4197ae196ae0 (from 8b6c03eb4d81ed75a4c72445c1f3b6d43af85099) Merge: a453078 8b6c03e Author: David Greminger <[email protected]> Date: Fri Sep 15 16:34:54 2017 +0200 Merge branch 'really-uniquenamer' of https://github.com/lsv/OneupUploaderBundle into lsv-really-uniquenamer diff --git a/.travis.yml b/.travis.yml index 1564c0e..0e69924 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 - 7.0 + - 7.1 - hhvm env: @@ -21,6 +21,7 @@ matrix: allow_failures: - php: hhvm - php: 7.0 + - php: 7.1 - env: SYMFONY_VERSION=dev-master include: @@ -43,3 +44,5 @@ before_script: - composer selfupdate - composer require symfony/http-kernel:${SYMFONY_VERSION} --prefer-source - composer install --dev --prefer-source + +script: ./vendor/bin/phpunit diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 01ae713..75d3518 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -175,6 +175,7 @@ abstract class AbstractController $event = new ValidationEvent($file, $this->getRequest(), $this->config, $this->type); $dispatcher->dispatch(UploadEvents::VALIDATION, $event); + $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $this->type), $event); } /** diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3374889..75d64b4 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,7 +22,7 @@ class Configuration implements ConfigurationInterface ->addDefaultsIfNotSet() ->children() ->enumNode('type') - ->values(array('filesystem', 'gaufrette')) + ->values(array('filesystem', 'gaufrette', 'flysystem')) ->defaultValue('filesystem') ->end() ->scalarNode('filesystem')->defaultNull()->end() @@ -65,7 +65,7 @@ class Configuration implements ConfigurationInterface ->children() ->scalarNode('service')->defaultNull()->end() ->enumNode('type') - ->values(array('filesystem', 'gaufrette')) + ->values(array('filesystem', 'gaufrette', 'flysystem')) ->defaultValue('filesystem') ->end() ->scalarNode('filesystem')->defaultNull()->end() @@ -90,6 +90,7 @@ class Configuration implements ConfigurationInterface ->booleanNode('enable_progress')->defaultFalse()->end() ->booleanNode('enable_cancelation')->defaultFalse()->end() ->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end() + ->booleanNode('root_folder')->defaultFalse()->end() ->end() ->end() ->end() diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 7f35224..c2c14eb 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -13,6 +13,10 @@ use Symfony\Component\DependencyInjection\Loader; class OneupUploaderExtension extends Extension { protected $storageServices = array(); + + /** + * @var ContainerBuilder + */ protected $container; protected $config; @@ -141,31 +145,44 @@ class OneupUploaderExtension extends Extension $config = &$this->config['chunks']['storage']; $storageClass = sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']); - if ($config['type'] === 'filesystem') { - $config['directory'] = is_null($config['directory']) ? - sprintf('%s/uploader/chunks', $this->container->getParameter('kernel.cache_dir')) : - $this->normalizePath($config['directory']) - ; - - $this->container - ->register('oneup_uploader.chunks_storage', sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type'])) - ->addArgument($config['directory']) - ; - } else { - $this->registerGaufretteStorage( - 'oneup_uploader.chunks_storage', - $storageClass, $config['filesystem'], - $config['sync_buffer_size'], - $config['stream_wrapper'], - $config['prefix'] - ); - - $this->container->setParameter('oneup_uploader.orphanage.class', 'Oneup\UploaderBundle\Uploader\Storage\GaufretteOrphanageStorage'); - - // enforce load distribution when using gaufrette as chunk - // torage to avoid moving files forth-and-back - $this->config['chunks']['load_distribution'] = true; + + switch($config['type']) { + case 'filesystem': + $config['directory'] = is_null($config['directory']) ? + sprintf('%s/uploader/chunks', $this->container->getParameter('kernel.cache_dir')) : + $this->normalizePath($config['directory']) + ; + + $this->container + ->register('oneup_uploader.chunks_storage', sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type'])) + ->addArgument($config['directory']) + ; + break; + case 'gaufrette': + case 'flysystem': + $this->registerFilesystem( + $config['type'], + 'oneup_uploader.chunks_storage', + $storageClass, $config['filesystem'], + $config['sync_buffer_size'], + $config['stream_wrapper'], + $config['prefix'] + ); + + $this->container->setParameter( + 'oneup_uploader.orphanage.class', + sprintf('Oneup\UploaderBundle\Uploader\Storage\%sOrphanageStorage', ucfirst($config['type'])) + ); + + // enforce load distribution when using gaufrette as chunk + // torage to avoid moving files forth-and-back + $this->config['chunks']['load_distribution'] = true; + break; + default: + throw new \InvalidArgumentException(sprintf('Filesystem "%s" is invalid', $config['type'])); + break; } + } protected function createStorageService(&$config, $key, $orphanage = false) @@ -181,26 +198,34 @@ class OneupUploaderExtension extends Extension $storageName = sprintf('oneup_uploader.storage.%s', $key); $storageClass = sprintf('%%oneup_uploader.storage.%s.class%%', $config['type']); - if ($config['type'] == 'filesystem') { - $config['directory'] = is_null($config['directory']) ? - sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) : - $this->normalizePath($config['directory']) - ; - - $this->container - ->register($storageName, $storageClass) - ->addArgument($config['directory']) - ; - } - - if ($config['type'] == 'gaufrette') { - $this->registerGaufretteStorage( - $storageName, - $storageClass, - $config['filesystem'], - $config['sync_buffer_size'], - $config['stream_wrapper'] - ); + switch ($config['type']) { + case 'filesystem': + // root_folder is true, remove the mapping name folder from path + $folder = $this->config['mappings'][$key]['root_folder'] ? '' : $key; + + $config['directory'] = is_null($config['directory']) ? + sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $folder) : + $this->normalizePath($config['directory']) + ; + + $this->container + ->register($storageName, $storageClass) + ->addArgument($config['directory']) + ; + break; + case 'gaufrette': + case 'flysystem': + $this->registerFilesystem( + $config['type'], + $storageName, + $storageClass, + $config['filesystem'], + $config['sync_buffer_size'], + $config['stream_wrapper'] + ); + break; + default: + break; } $storageService = new Reference($storageName); @@ -227,12 +252,22 @@ class OneupUploaderExtension extends Extension return $storageService; } - protected function registerGaufretteStorage($key, $class, $filesystem, $buffer, $streamWrapper = null, $prefix = '') + protected function registerFilesystem($type, $key, $class, $filesystem, $buffer, $streamWrapper = null, $prefix = '') { - if(!class_exists('Gaufrette\\Filesystem')) - throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a chunk storage service.'); + switch ($type) { + case 'gaufrette': + if (!class_exists('Gaufrette\\Filesystem')) { + throw new InvalidArgumentException('You have to install knplabs/knp-gaufrette-bundle in order to use it as a chunk storage service.'); + } + break; + case 'flysystem': + if (!class_exists('League\\Flysystem\\Filesystem')) { + throw new InvalidArgumentException('You have to install oneup/flysystem-bundle in order to use it as a chunk storage service.'); + } + break; + } - if(strlen($filesystem) <= 0) + if (strlen($filesystem) <= 0) throw new ServiceNotFoundException('Empty service name'); $streamWrapper = $this->normalizeStreamWrapper($streamWrapper); @@ -242,8 +277,7 @@ class OneupUploaderExtension extends Extension ->addArgument(new Reference($filesystem)) ->addArgument($this->getValueInBytes($buffer)) ->addArgument($streamWrapper) - ->addArgument($prefix) - ; + ->addArgument($prefix); } protected function getMaxUploadSize($input) @@ -260,11 +294,14 @@ class OneupUploaderExtension extends Extension // see: http://www.php.net/manual/en/function.ini-get.php $input = trim($input); $last = strtolower($input[strlen($input) - 1]); + $numericInput = (float) substr($input, 0, -1); switch ($last) { - case 'g': $input *= 1024; - case 'm': $input *= 1024; - case 'k': $input *= 1024; + case 'g': $numericInput *= 1024; + case 'm': $numericInput *= 1024; + case 'k': $numericInput *= 1024; + + return $numericInput; } return $input; diff --git a/README.md b/README.md index daa5eac..1daa930 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,23 @@ OneupUploaderBundle =================== -The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following Javascript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md). +The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md). -* [FineUploader](http://fineuploader.com/) -* [jQuery File Uploader](http://blueimp.github.io/jQuery-File-Upload/) -* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/) -* [Uploadify](http://www.uploadify.com/) -* [FancyUpload](http://digitarald.de/project/fancyupload/) -* [MooUpload](https://github.com/juanparati/MooUpload) -* [Plupload](http://www.plupload.com/) * [Dropzone](http://www.dropzonejs.com/) +* [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/) +* [Plupload](http://www.plupload.com/) +* [FineUploader](http://fineuploader.com/) +* [FancyUpload](http://digitarald.de/project/fancyupload/) (based on MooTools) +* [MooUpload](https://github.com/juanparati/MooUpload) (based on MooTools) +* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/) (the YUI library is no longer maintained) +* [UploadiFive](http://www.uploadify.com/) ($ 5.00) + Features included: * Multiple file uploads handled by your chosen frontend library * Chunked uploads -* Supports [Gaufrette](https://github.com/KnpLabs/Gaufrette) and/or local filesystem +* Support for: [Gaufrette](https://github.com/KnpLabs/Gaufrette) / [Flysystem](https://github.com/thephpleague/flysystem) / local filesystem * Provides an orphanage for cleaning up orphaned files * Supports [Session upload progress & cancelation of uploads](http://php.net/manual/en/session.upload-progress.php) as of PHP 5.4 * Fully unit tested @@ -33,6 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- +* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). * Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57). * If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320). * Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md). diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml index bf580bf..1f51fb2 100644 --- a/Resources/config/errorhandler.xml +++ b/Resources/config/errorhandler.xml @@ -12,7 +12,9 @@ <services> <service id="oneup_uploader.error_handler.noop" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.fineuploader" class="%oneup_uploader.error_handler.noop.class%" public="false" /> - <service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false" /> + <service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false"> + <argument type="service" id="translator"/> + </service> <service id="oneup_uploader.error_handler.uploadify" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.yui3" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 0e80c99..4389640 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -6,11 +6,13 @@ <parameters> <parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter> <parameter key="oneup_uploader.chunks_storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\GaufretteStorage</parameter> + <parameter key="oneup_uploader.chunks_storage.flysystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage</parameter> <parameter key="oneup_uploader.chunks_storage.filesystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage</parameter> <parameter key="oneup_uploader.namer.urlsafename.class">Oneup\UploaderBundle\Uploader\Naming\UrlSafeNamer</parameter> <parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter> <parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter> <parameter key="oneup_uploader.storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter> + <parameter key="oneup_uploader.storage.flysystem.class">Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage</parameter> <parameter key="oneup_uploader.storage.filesystem.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage</parameter> <parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemOrphanageStorage</parameter> <parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter> diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index fd6d87a..2aa007b 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -1,7 +1,7 @@ Using Chunked Uploads ===================== -Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. +Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabled, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. ```js $(document).ready(function() @@ -82,6 +82,6 @@ See the [Use Chunked Uploads behind Load Balancers](load_balancers.md) section i The ChunkManager can be forced to clean up old and orphanaged chunks by using the command provided by the OneupUploaderBundle. - $> php app/console oneup:uploader:clean-chunks + $> php app/console oneup:uploader:clear-chunks This parameter will clean all chunk files older than the `maxage` value in your configuration. diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index 6b0d248..a7cee8a 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -38,6 +38,7 @@ oneup_uploader: allowed_mimetypes: [] disallowed_mimetypes: [] error_handler: oneup_uploader.error_handler.noop + root_folder: false # Set max_size to -1 for gracefully downgrade this number to the systems max upload size. max_size: 9223372036854775807 diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md index ccb915e..3471492 100644 --- a/Resources/doc/custom_logic.md +++ b/Resources/doc/custom_logic.md @@ -11,20 +11,31 @@ In almost every use case you need to further process uploaded files. For example To listen to one of these events you need to create an `EventListener`. ```php -namespace Acme\HelloBundle\EventListener; +namespace AppBundle\EventListener; +use Doctrine\Common\Persistence\ObjectManager; use Oneup\UploaderBundle\Event\PostPersistEvent; class UploadListener { - public function __construct($doctrine) + /** + * @var ObjectManager + */ + private $om; + + public function __construct(ObjectManager $om) { - $this->doctrine = $doctrine; + $this->om = $om; } public function onUpload(PostPersistEvent $event) { //... + + //if everything went fine + $response = $event->getResponse(); + $response['success'] = true; + return $response; } } ``` @@ -33,7 +44,7 @@ And register it in your `services.xml`. ```xml <services> - <service id="acme_hello.upload_listener" class="Acme\HelloBundle\EventListener\UploadListener"> + <service id="app.upload_listener" class="AppBundle\EventListener\UploadListener"> <argument type="service" id="doctrine" /> <tag name="kernel.event_listener" event="oneup_uploader.post_persist" method="onUpload" /> </service> @@ -43,8 +54,8 @@ And register it in your `services.xml`. ```yml services: acme_hello.upload_listener: - class: Acme\HelloBundle\EventListener\UploadListener - argument: ["@doctrine"] + class: AppBundle\EventListener\UploadListener + arguments: ["@doctrine.orm.entity_manager"] tags: - { name: kernel.event_listener, event: oneup_uploader.post_persist, method: onUpload } ``` @@ -114,6 +125,6 @@ use Symfony\Component\HttpFoundation\File\Exception\UploadException; public function onUpload(PostPersistEvent $event) { // Remember to remove the already uploaded file - throw new UploadException('Nope, I dont do files'); + throw new UploadException('Nope, I don\'t do files.'); } ``` diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md index 7ac3fc1..37be120 100644 --- a/Resources/doc/custom_namer.md +++ b/Resources/doc/custom_namer.md @@ -27,7 +27,7 @@ First, create a custom namer which implements ```Oneup\UploaderBundle\Uploader\N ```php <?php -namespace Acme\DemoBundle; +namespace AppBundle\Uploader\Naming; use Oneup\UploaderBundle\Uploader\File\FileInterface; use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; @@ -41,7 +41,7 @@ class CatNamer implements NamerInterface } ``` -To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. +To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. The namer should return an unique name to avoid issues if the file already exists. Next, register your created namer as a service in your `services.xml` @@ -53,8 +53,8 @@ Next, register your created namer as a service in your `services.xml` ```yml services: - acme_demo.custom_namer: - class: Acme\DemoBundle\CatNamer + app.cat_namer: + class: AppBundle\Uploader\Naming\CatNamer ``` Now you can use your custom service by adding it to your configuration: @@ -63,7 +63,68 @@ Now you can use your custom service by adding it to your configuration: oneup_uploader: mappings: gallery: - namer: acme_demo.custom_namer + namer: app.cat_namer ``` Every file uploaded through the `Controller` of this mapping will be named with your custom namer. + +## Change the directory structure + +With the `NameInterface` you can change the directory structure to provide a better files organization or to use your own existing structure. For example, you need to separate the uploaded files by users with a `user_id` folder. + +You need to inject the `security.token_storage` service to your namer. + +```xml +<services> + <service id="acme_demo.custom_namer" class="Acme\DemoBundle\CatNamer"> + <argument type="service" id="security.token_storage"/> + </service> +</services> +``` + +```yml +services: + acme_demo.custom_namer: + class: Acme\DemoBundle\CatNamer + arguments: ["@security.token_storage"] +``` + +Now you can use the service to get the logged user id and return the custom directory like below: + +```php +<?php + +namespace Acme\DemoBundle; + +use Oneup\UploaderBundle\Uploader\File\FileInterface; +use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; + +class CatNamer implements NamerInterface +{ + private $tokenStorage; + + public function __construct(TokenStorage $tokenStorage){ + $this->tokenStorage = $tokenStorage; + } + + /** + * Creates a user directory name for the file being uploaded. + * + * @param FileInterface $file + * @return string The directory name. + */ + public function name(FileInterface $file) + { + $userId = $this->tokenStorage->getToken()->getUser()->getId(); + + return sprintf('%s/%s.%s', + $userId, + uniqid(), + $file->getExtension() + ); + } +} +``` + +Every file uploaded through the `Controller` of this mapping will be named with your new directory structure. diff --git a/Resources/doc/custom_validator.md b/Resources/doc/custom_validator.md index 2d5b5f0..1a4d77d 100644 --- a/Resources/doc/custom_validator.md +++ b/Resources/doc/custom_validator.md @@ -53,3 +53,5 @@ services: tags: - { name: kernel.event_listener, event: oneup_uploader.validation, method: onValidate } ``` + +Since version 1.6 you can listen to an event thrown for every uploader specifically. The name for the event is `oneup_uploader.validation.{type}` where `{type}` represents the config key of the uploader you want to target. diff --git a/Resources/doc/flysystem_storage.md b/Resources/doc/flysystem_storage.md new file mode 100644 index 0000000..76aa1ea --- /dev/null +++ b/Resources/doc/flysystem_storage.md @@ -0,0 +1,75 @@ +Use Flysystem as Storage layer +============================== + +Flysystem is an abstract storage layer you can use to store your uploaded files. An explanation why you should use an abstraction storage layer comes from the _Why use Gaufrette_ section on [the Gaufrette Repo](https://github.com/KnpLabs/Gaufrette): + +> The filesystem abstraction layer permits you to develop your application without the need to know were all those medias will be stored and how. +> +> Another advantage of this is the possibility to update the files location without any impact on the code apart from the definition of your filesystem. In example, if your project grows up very fast and if your server reaches its limits, you can easily move your medias in an Amazon S3 server or any other solution. + +In order to use Flysystem with OneupUploaderBundle, be sure to follow these steps: + +## Install OneupFlysystemBundle + +Add the OneupFlysystemBundle to your composer.json file. + +```js +{ + "require": { + "oneup/flysystem-bundle": "1.4.*" + } +} +``` + +And update your dependencies through composer. + + $> php composer.phar update oneup/flysystem-bundle + +After installing, enable the bundle in your AppKernel: + +``` php +<?php +// app/AppKernel.php + +public function registerBundles() +{ + $bundles = array( + // ... + new Oneup\FlysystemBundle\OneupFlysystemBundle(), + ); +} +``` + +## Configure your Filesystems + +The following is a sample configuration for the OneupFlysystemBundle. It will create a flysystem service called `oneup_flysystem.gallery_filesystem` which can be used in the OneupUploaderBundle. For a complete list of features refer to the [official documentation](https://github.com/1up-lab/OneupFlysystemBundle). + +```yml +# app/config/config.yml + +oneup_flysystem: + adapters: + acme.flysystem_adapter: + awss3v3: + client: acme.s3_client + bucket: ~ + prefix: ~ + filesystems: + gallery: + adapter: acme.flysystem_adapter +``` + +## Configure your mappings + +Activate Flysystem by switching the `type` property to `flysystem` and pass the Flysystem filesystem configured in the previous step. + +```yml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + storage: + type: flysystem + filesystem: oneup_flysystem.gallery_filesystem +``` diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md index 66fc318..875fb3d 100644 --- a/Resources/doc/frontend_dropzone.md +++ b/Resources/doc/frontend_dropzone.md @@ -4,9 +4,9 @@ Use Dropzone in your Symfony2 application Download [Dropzone](http://www.dropzonejs.com/) and include it in your template. Connect the `action` property of the form to the dynamic route `_uploader_{mapping_name}`. ```html -<script type="text/javascript" src="https://rawgithub.com/enyo/dropzone/master/downloads/dropzone.js"></script> +<script type="text/javascript" src="https://raw.github.com/enyo/dropzone/master/dist/dropzone.js"></script> -<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone"> +<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" style="width:200px; height:200px; border:4px dashed black"> </form> ``` diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md index cd8a019..22fbb16 100644 --- a/Resources/doc/frontend_fineuploader.md +++ b/Resources/doc/frontend_fineuploader.md @@ -1,26 +1,27 @@ Use FineUploader ================ -Download [FineUploader](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. +Download [FineUploader 5](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. This example is based on the [UI Mode](http://docs.fineuploader.com/branch/master/quickstart/01-getting-started.html) of FineUploader. ```html -<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> -<script type="text/javascript" src="js/jquery.fineuploader-3.4.1.js"></script> +<link href="fine-uploader/fine-uploader-new.min.css" rel="stylesheet"> +<script type="text/javascript" src="fine-uploader/fine-uploader.min.js"></script> <script type="text/javascript"> -$(document).ready(function() -{ var uploader = new qq.FineUploader({ - element: $('#uploader')[0], + element: document.getElementById('fine-uploader'), request: { endpoint: "{{ oneup_uploader_endpoint('gallery') }}" } }); -}); </script> -<div id="uploader"></div> +<div id="fine-uploader"></div> ``` +You can find a fully example of all available settings on the [official documentation](http://docs.fineuploader.com/branch/master/quickstart/02-setting_options.html). + +If you are using Fine Uploader UI, as described in this example, you **MUST** include a template in your document/markup. You can use the ``default.html`` file in the templates directory bundled with the FineUploader library and customize it as desired. You even can use an inline template. See the official [styling documentation page](http://docs.fineuploader.com/branch/master/features/styling.html) for more details. + Configure the OneupUploaderBundle to use the correct controller: ```yaml diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 4178e9e..3942d44 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -25,7 +25,7 @@ framework: Perform the following steps to install and use the basic functionality of the OneupUploaderBundle: -* Download OnueupUploaderBundle using Composer +* Download OneupUploaderBundle using Composer * Enable the bundle * Configure the bundle * Prepare your frontend @@ -34,19 +34,9 @@ Perform the following steps to install and use the basic functionality of the On Add OneupUploaderBundle to your composer.json using the following construct: -```js -{ - "require": { - "oneup/uploader-bundle": "~1.4" - } -} -``` - -Now tell composer to download the bundle by running the following command: - - $> php composer.phar update oneup/uploader-bundle + $ composer require oneup/uploader-bundle "~1.4" -Composer will now fetch and install this bundle in the vendor directory ```vendor/oneup``` +Composer will install the bundle to your project's ``vendor/oneup/uploader-bundle`` directory. ### Step 2: Enable the bundle @@ -75,7 +65,7 @@ This bundle was designed to just work out of the box. The only thing you have to oneup_uploader: mappings: gallery: - frontend: blueimp # or any uploader you use in the frontend + frontend: dropzone # or any uploader you use in the frontend ``` To enable the dynamic routes, add the following to your routing configuration file. @@ -88,13 +78,43 @@ oneup_uploader: type: uploader ``` -The default directory that is used to upload files to is `web/uploads/{mapping_name}`. +The default directory that is used to upload files to is `web/uploads/{mapping_name}`. In case you want to avoid a separated mapping folder, you can set `root_folder: true` and the default directory will be `web/uploads`. + +```yaml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + root_folder: true +``` > It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you. +> You can improve the directory structure checking the "[Change the directory structure](custom_namer.md#change-the-directory-structure)". -### Step 4: Prepare your frontend +If you want to use your own path, for example /data/uploads : -No matter what library you choose, be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows: +```yaml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + storage: + directory: "%kernel.root_dir%/../data/uploads/" +``` + +### Step 4: Check if the bundle is working correctly + +No matter which JavaScript library you are going to use ultimately, we recommend to test the bundle with Dropzone first, since this one features the easiest setup process: + +1. [Install Dropzone](frontend_dropzone.md) +1. Drag a file onto the dashed rectangle. The upload should start immediately. However, you won't get any visual feedback yet. +1. Check your `web/uploads/gallery` directory: If you see the file there, the OneupUploaderBundle is working correctly. If you don't have that folder, create it manually and try again. + +### Step 5: Prepare your real frontend + +Now it's up to you to decide for a JavaScript library or write your own. Be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows: ```php $helper = $this->container->get('oneup_uploader.templating.uploader_helper'); @@ -107,14 +127,14 @@ or in a Twig template you can use the `oneup_uploader_endpoint` function: So if you take the mapping described before, the generated route name would be `_uploader_gallery`. Follow one of the listed guides to include your frontend: -* [Use FineUploader](frontend_fineuploader.md) +* [Use Dropzone](frontend_dropzone.md) * [Use jQuery File Upload](frontend_blueimp.md) -* [Use YUI3 Uploader](frontend_yui3.md) -* [Use Uploadify](frontend_uploadify.md) +* [Use Plupload](frontend_plupload.md) +* [Use FineUploader](frontend_fineuploader.md) * [Use FancyUpload](frontend_fancyupload.md) * [Use MooUpload](frontend_mooupload.md) -* [Use Plupload](frontend_plupload.md) -* [Use Dropzone](frontend_dropzone.md) +* [Use YUI3 Uploader](frontend_yui3.md) +* [Use Uploadify](frontend_uploadify.md) ## Next steps @@ -125,6 +145,7 @@ some more advanced features. * [Return custom data to frontend](response.md) * [Enable chunked uploads](chunked_uploads.md) * [Using the Orphanage](orphanage.md) +* [Use Flysystem as storage layer](flysystem_storage.md) * [Use Gaufrette as storage layer](gaufrette_storage.md) * [Include your own Namer](custom_namer.md) * [Use custom error handlers](custom_error_handler.md) diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php index 7ba1307..871e687 100644 --- a/Tests/Controller/BlueimpValidationTest.php +++ b/Tests/Controller/BlueimpValidationTest.php @@ -2,6 +2,7 @@ namespace Oneup\UploaderBundle\Tests\Controller; +use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Component\HttpFoundation\File\UploadedFile; use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest; use Oneup\UploaderBundle\UploadEvents; @@ -11,6 +12,7 @@ class BlueimpValidationTest extends AbstractValidationTest public function testAgainstMaxSize() { // assemble a request + /** @var Client $client */ $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); @@ -20,6 +22,7 @@ class BlueimpValidationTest extends AbstractValidationTest //$this->assertTrue($response->isNotSuccessful()); $this->assertEquals($response->headers->get('Content-Type'), 'application/json'); $this->assertCount(0, $this->getUploadedFiles()); + $this->assertFalse(strpos($response->getContent(), 'error.maxsize'), "Failed to translate error id into lang"); } public function testEvents() diff --git a/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php new file mode 100644 index 0000000..102e954 --- /dev/null +++ b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php @@ -0,0 +1,125 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Uploader\Storage; + +use League\Flysystem\File; +use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage; +use Oneup\UploaderBundle\Uploader\File\FlysystemFile; +use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Finder; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; + +use League\Flysystem\Adapter\Local as Adapter; +use League\Flysystem\Filesystem as FSAdapter; +use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage; + +class FlysystemOrphanageStorageTest extends OrphanageTest +{ + protected $chunkDirectory; + protected $chunksKey = 'chunks'; + protected $orphanageKey = 'orphanage'; + + public function setUp() + { + $this->numberOfPayloads = 5; + $this->realDirectory = sys_get_temp_dir() . '/storage'; + $this->chunkDirectory = $this->realDirectory .'/' . $this->chunksKey; + $this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey; + $this->payloads = array(); + + $filesystem = new Filesystem(); + $filesystem->mkdir($this->realDirectory); + $filesystem->mkdir($this->chunkDirectory); + $filesystem->mkdir($this->tempDirectory); + + if (!$this->checkIfTempnameMatchesAfterCreation()) { + $this->markTestSkipped('Temporary directories do not match'); + } + + $adapter = new Adapter($this->realDirectory, true); + $filesystem = new FSAdapter($adapter); + + $this->storage = new Storage($filesystem, 100000); + + $chunkStorage = new ChunkStorage($filesystem, 100000, null, 'chunks'); + + // create orphanage + $session = new Session(new MockArraySessionStorage()); + $session->start(); + + $config = array('directory' => 'orphanage'); + + $this->orphanage = new FlysystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat'); + + for ($i = 0; $i < $this->numberOfPayloads; $i ++) { + // create temporary file as if it was reassembled by the chunk manager + $file = tempnam($this->chunkDirectory, 'uploader'); + + $pointer = fopen($file, 'w+'); + fwrite($pointer, str_repeat('A', 1024), 1024); + fclose($pointer); + + //file key needs to be relative to the root of the flysystem filesystem + $fileKey = str_replace($this->realDirectory, '', $file); + + $this->payloads[] = new FlysystemFile(new File($filesystem, $fileKey), $filesystem); + } + } + + public function testUpload() + { + for ($i = 0; $i < $this->numberOfPayloads; $i ++) { + $this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg'); + } + + $finder = new Finder(); + $finder->in($this->tempDirectory)->files(); + $this->assertCount($this->numberOfPayloads, $finder); + + $finder = new Finder(); + // exclude the orphanage and the chunks + $finder->in($this->realDirectory)->exclude(array($this->orphanageKey, $this->chunksKey))->files(); + $this->assertCount(0, $finder); + } + + public function testUploadAndFetching() + { + for ($i = 0; $i < $this->numberOfPayloads; $i ++) { + $this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg'); + } + + $finder = new Finder(); + $finder->in($this->tempDirectory)->files(); + $this->assertCount($this->numberOfPayloads, $finder); + + $finder = new Finder(); + $finder->in($this->realDirectory) + ->exclude(array($this->orphanageKey, $this->chunksKey)) + ->files(); + $this->assertCount(0, $finder); + + $files = $this->orphanage->uploadFiles(); + + $this->assertTrue(is_array($files)); + $this->assertCount($this->numberOfPayloads, $files); + + $finder = new Finder(); + $finder->in($this->tempDirectory)->files(); + $this->assertCount(0, $finder); + + $finder = new Finder(); + $finder->in($this->realDirectory)->files(); + $this->assertCount($this->numberOfPayloads, $finder); + } + + public function checkIfTempnameMatchesAfterCreation() + { + $testName = tempnam($this->chunkDirectory, 'uploader'); + $result = strpos($testName, $this->chunkDirectory) === 0; + unlink($testName); + + return $result; + } +} diff --git a/Tests/Uploader/Storage/FlysystemStorageTest.php b/Tests/Uploader/Storage/FlysystemStorageTest.php new file mode 100644 index 0000000..bdd43e9 --- /dev/null +++ b/Tests/Uploader/Storage/FlysystemStorageTest.php @@ -0,0 +1,61 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Uploader\Storage; + +use League\Flysystem\Adapter\Local as Adapter; +use League\Flysystem\Filesystem as FSAdapter; +use Oneup\UploaderBundle\Uploader\File\FilesystemFile; +use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpFoundation\File\UploadedFile; + +class FlysystemStorageTest extends \PHPUnit_Framework_TestCase +{ + protected $directory; + + /** + * @var Storage + */ + protected $storage; + protected $file; + + public function setUp() + { + $this->directory = sys_get_temp_dir() . '/storage'; + + // create temporary file + $this->file = tempnam(sys_get_temp_dir(), 'uploader'); + + $pointer = fopen($this->file, 'w+'); + fwrite($pointer, str_repeat('A', 1024), 1024); + fclose($pointer); + + $adapter = new Adapter($this->directory, true); + $filesystem = new FSAdapter($adapter); + + $this->storage = new Storage($filesystem, 100000); + } + + public function testUpload() + { + $payload = new FilesystemFile(new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true)); + $this->storage->upload($payload, 'notsogrumpyanymore.jpeg'); + + $finder = new Finder(); + $finder->in($this->directory)->files(); + + $this->assertCount(1, $finder); + + foreach ($finder as $file) { + $this->assertEquals($file->getFilename(), 'notsogrumpyanymore.jpeg'); + $this->assertEquals($file->getSize(), 1024); + } + } + + public function tearDown() + { + $filesystem = new Filesystem(); + $filesystem->remove($this->directory); + } +} diff --git a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php index 418298c..a9e55cb 100644 --- a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php +++ b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php @@ -113,6 +113,6 @@ class GaufretteOrphanageStorageTest extends OrphanageTest public function checkIfTempnameMatchesAfterCreation() { - return strpos(tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0; + return strpos(@tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0; } } diff --git a/Tests/Uploader/Storage/OrphanageTest.php b/Tests/Uploader/Storage/OrphanageTest.php index 836ab86..c539e7f 100644 --- a/Tests/Uploader/Storage/OrphanageTest.php +++ b/Tests/Uploader/Storage/OrphanageTest.php @@ -2,13 +2,18 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; +use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; -abstract class OrphanageTest extends \PHPUnit_Framework_Testcase +abstract class OrphanageTest extends \PHPUnit_Framework_TestCase { protected $tempDirectory; protected $realDirectory; + + /** + * @var \Oneup\UploaderBundle\Uploader\Storage\OrphanageStorageInterface + */ protected $orphanage; protected $storage; protected $payloads; diff --git a/Uploader/Chunk/Storage/FlysystemStorage.php b/Uploader/Chunk/Storage/FlysystemStorage.php new file mode 100644 index 0000000..19e7a44 --- /dev/null +++ b/Uploader/Chunk/Storage/FlysystemStorage.php @@ -0,0 +1,152 @@ +<?php +namespace Oneup\UploaderBundle\Uploader\Chunk\Storage; + +use Oneup\UploaderBundle\Uploader\File\FlysystemFile; +use League\Flysystem\Filesystem; +use Symfony\Component\HttpFoundation\File\UploadedFile; + +class FlysystemStorage implements ChunkStorageInterface +{ + + protected $unhandledChunk; + protected $prefix; + protected $streamWrapperPrefix; + + /** + * @var Filesystem + */ + private $filesystem; + + public $bufferSize; + + public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix, $prefix) + { + if ( + ! method_exists($filesystem, 'readStream') + || + ! method_exists($filesystem, 'putStream') + ) { + throw new \InvalidArgumentException('The filesystem used as chunk storage must streamable'); + } + + $this->filesystem = $filesystem; + $this->bufferSize = $bufferSize; + $this->prefix = $prefix; + $this->streamWrapperPrefix = $streamWrapperPrefix; + } + + public function clear($maxAge, $prefix = null) + { + $prefix = $prefix ? :$this->prefix; + $matches = $this->filesystem->listFiles($prefix); + + $now = time(); + $toDelete = array(); + + // Collect the directories that are old, + // this also means the files inside are old + // but after the files are deleted the dirs + // would remain + foreach ($matches['dirs'] as $key) { + if ($maxAge <= $now-$this->filesystem->getTimestamp($key)) { + $toDelete[] = $key; + } + } + // The same directory is returned for every file it contains + array_unique($toDelete); + foreach ($matches['keys'] as $key) { + if ($maxAge <= $now-$this->filesystem->getTimestamp($key)) { + $this->filesystem->delete($key); + } + } + + foreach ($toDelete as $key) { + // The filesystem will throw exceptions if + // a directory is not empty + try { + $this->filesystem->delete($key); + } catch (\Exception $e) { + continue; + } + } + } + + public function addChunk($uuid, $index, UploadedFile $chunk, $original) + { + $this->unhandledChunk = array( + 'uuid' => $uuid, + 'index' => $index, + 'chunk' => $chunk, + 'original' => $original + ); + } + + public function assembleChunks($chunks, $removeChunk, $renameChunk) + { + // the index is only added to be in sync with the filesystem storage + $path = $this->prefix.'/'.$this->unhandledChunk['uuid'].'/'; + $filename = $this->unhandledChunk['index'].'_'.$this->unhandledChunk['original']; + + if (empty($chunks)) { + $target = $filename; + } else { + sort($chunks, SORT_STRING | SORT_FLAG_CASE); + $target = pathinfo($chunks[0], PATHINFO_BASENAME); + } + + + if ($this->unhandledChunk['index'] === 0) { + // if it's the first chunk overwrite the already existing part + // to avoid appending to earlier failed uploads + $handle = fopen($path . '/' . $target, 'w'); + } else { + $handle = fopen($path . '/' . $target, 'a'); + } + + $this->filesystem->putStream($path . $target, $handle); + if ($renameChunk) { + $name = preg_replace('/^(\d+)_/', '', $target); + /* The name can only match if the same user in the same session is + * trying to upload a file under the same name AND the previous upload failed, + * somewhere between this function, and the cleanup call. If that happened + * the previous file is unaccessible by the user, but if it is not removed + * it will block the user from trying to re-upload it. + */ + if ($this->filesystem->has($path.$name)) { + $this->filesystem->delete($path.$name); + } + + $this->filesystem->rename($path.$target, $path.$name); + $target = $name; + } + $uploaded = $this->filesystem->get($path.$target); + + if (!$renameChunk) { + return $uploaded; + } + + return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix); + } + + public function cleanup($path) + { + $this->filesystem->delete($path); + } + + public function getChunks($uuid) + { + $results = $this->filesystem->listFiles($this->prefix.'/'.$uuid); + return preg_grep('/^.+\/(\d+)_/', $results['keys']); + } + + public function getFilesystem() + { + return $this->filesystem; + } + + public function getStreamWrapperPrefix() + { + return $this->streamWrapperPrefix; + } + +} diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php index c8839b7..be5e088 100644 --- a/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -5,12 +5,23 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler; use Exception; use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; +use Symfony\Component\Translation\TranslatorInterface; class BlueimpErrorHandler implements ErrorHandlerInterface { + /** + * @var TranslatorInterface + */ + private $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + public function addException(AbstractResponse $response, Exception $exception) { - $message = $exception->getMessage(); + $message = $this->translator->trans($exception->getMessage(), array(), 'OneupUploaderBundle'); $response->addToOffset(array('error' => $message), array('files')); } } diff --git a/Uploader/File/FlysystemFile.php b/Uploader/File/FlysystemFile.php new file mode 100644 index 0000000..dc36e69 --- /dev/null +++ b/Uploader/File/FlysystemFile.php @@ -0,0 +1,48 @@ +<?php +namespace Oneup\UploaderBundle\Uploader\File; + +use League\Flysystem\File; +use League\Flysystem\Filesystem; + +class FlysystemFile extends File implements FileInterface +{ + + protected $streamWrapperPrefix; + protected $mimeType; + + public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null) + { + parent::__construct($filesystem, $file->getPath()); + $this->streamWrapperPrefix = $streamWrapperPrefix; + } + + /** + * Returns the path of the file + * + * @return string + */ + public function getPathname() + { + return $this->getPath(); + } + + /** + * Returns the basename of the file + * + * @return string + */ + public function getBasename() + { + return pathinfo($this->getPath(), PATHINFO_BASENAME); + } + + /** + * Returns the guessed extension of the file + * + * @return mixed + */ + public function getExtension() + { + return pathinfo($this->getPath(), PATHINFO_EXTENSION); + } +} diff --git a/Uploader/Gaufrette/StreamManager.php b/Uploader/Gaufrette/StreamManager.php index 58868b8..7fcc83a 100644 --- a/Uploader/Gaufrette/StreamManager.php +++ b/Uploader/Gaufrette/StreamManager.php @@ -25,11 +25,9 @@ class StreamManager protected function ensureRemotePathExists($path) { - // this is a somehow ugly workaround introduced - // because the stream-mode is not able to create - // subdirectories. - if(!$this->filesystem->has($path)) + if(!$this->filesystem->has($path)) { $this->filesystem->write($path, '', true); + } } protected function openStream(Stream $stream, $mode) diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php index 9352b4e..9442712 100644 --- a/Uploader/Orphanage/OrphanageManager.php +++ b/Uploader/Orphanage/OrphanageManager.php @@ -32,7 +32,7 @@ class OrphanageManager // Really ugly solution to clearing the orphanage on gaufrette $class = $this->container->getParameter('oneup_uploader.orphanage.class'); if ($class === 'Oneup\UploaderBundle\Uploader\Storage\GaufretteOrphanageStorage') { - $chunkStorage = $this->container->get('oneup_uploader.chunks_storage '); + $chunkStorage = $this->container->get('oneup_uploader.chunks_storage'); $chunkStorage->clear($this->config['maxage'], $this->config['directory']); return; diff --git a/Uploader/Storage/FilesystemOrphanageStorage.php b/Uploader/Storage/FilesystemOrphanageStorage.php index ed6e4f6..8888e16 100644 --- a/Uploader/Storage/FilesystemOrphanageStorage.php +++ b/Uploader/Storage/FilesystemOrphanageStorage.php @@ -48,7 +48,7 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS $return = array(); foreach ($files as $file) { - $return[] = $this->storage->upload(new FilesystemFile(new File($file->getPathname())), str_replace($this->getFindPath(), '', $file)); + $return[] = $this->storage->upload(new FilesystemFile(new File($file->getPathname())), ltrim(str_replace($this->getFindPath(), '', $file), "/")); } return $return; diff --git a/Uploader/Storage/FlysystemOrphanageStorage.php b/Uploader/Storage/FlysystemOrphanageStorage.php new file mode 100644 index 0000000..376deb5 --- /dev/null +++ b/Uploader/Storage/FlysystemOrphanageStorage.php @@ -0,0 +1,99 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Storage; + +use League\Flysystem\File; +use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage; +use Oneup\UploaderBundle\Uploader\File\FileInterface; +use Oneup\UploaderBundle\Uploader\File\FlysystemFile; +use Symfony\Component\HttpFoundation\Session\SessionInterface; + +class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageStorageInterface +{ + protected $storage; + protected $session; + protected $chunkStorage; + protected $config; + protected $type; + + /** + * @param StorageInterface $storage + * @param SessionInterface $session + * @param ChunkStorage $chunkStorage This class is only used if the gaufrette chunk storage is used. + * @param $config + * @param $type + */ + public function __construct(StorageInterface $storage, SessionInterface $session, ChunkStorage $chunkStorage, $config, $type) + { + /* + * initiate the storage on the chunk storage's filesystem + * the stream wrapper is useful for metadata. + */ + parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->bufferSize, $chunkStorage->getStreamWrapperPrefix()); + + $this->storage = $storage; + $this->chunkStorage = $chunkStorage; + $this->session = $session; + $this->config = $config; + $this->type = $type; + } + + public function upload(FileInterface $file, $name, $path = null) + { + if(!$this->session->isStarted()) + throw new \RuntimeException('You need a running session in order to run the Orphanage.'); + + return parent::upload($file, $name, $this->getPath()); + } + + public function uploadFiles(array $files = null) + { + try { + if (null === $files) { + $files = $this->getFiles(); + } + $return = array(); + + foreach ($files as $key => $file) { + try { + $return[] = $this->storage->upload($file, str_replace($this->getPath(), '', $key)); + } catch (\Exception $e) { + // well, we tried. + continue; + } + } + + return $return; + } catch (\Exception $e) { + return array(); + } + } + + public function getFiles() + { + $fileList = $this->chunkStorage + ->getFilesystem() + ->listContents($this->getPath()); + $files = array(); + + foreach ($fileList as $fileDetail) { + $key = $fileDetail['path']; + if ($fileDetail['type'] == 'file') { + $files[$key] = new FlysystemFile( + new File($this->chunkStorage->getFilesystem(), $key), + $this->chunkStorage->getFilesystem() + ); + } + } + + return $files; + } + + protected function getPath() + { + // the storage is initiated in the root of the filesystem, from where the orphanage directory + // should be relative. + return sprintf('%s/%s/%s', $this->config['directory'], $this->session->getId(), $this->type); + } + +} diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php new file mode 100644 index 0000000..aa2fa61 --- /dev/null +++ b/Uploader/Storage/FlysystemStorage.php @@ -0,0 +1,65 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Storage; + +use League\Flysystem\Filesystem; +use Oneup\UploaderBundle\Uploader\File\FileInterface; +use Oneup\UploaderBundle\Uploader\File\FlysystemFile; +use Symfony\Component\Filesystem\Filesystem as LocalFilesystem; + +class FlysystemStorage implements StorageInterface +{ + + /** + * @var null|string + */ + protected $streamWrapperPrefix; + + /** + * @var float + */ + protected $bufferSize; + + /** + * @var Filesystem + */ + private $filesystem; + + public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix = null) + { + $this->filesystem = $filesystem; + $this->bufferSize = $bufferSize; + $this->streamWrapperPrefix = $streamWrapperPrefix; + } + + public function upload(FileInterface $file, $name, $path = null) + { + $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name); + + if ($file instanceof FlysystemFile) { + if ($file->getFilesystem() == $this->filesystem) { + $file->getFilesystem()->rename($file->getPath(), $path); + + return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix); + } + } + + $stream = fopen($file->getPathname(), 'r+'); + $this->filesystem->putStream($name, $stream, array( + 'mimetype' => $file->getMimeType() + )); + if (is_resource($stream)) { + fclose($stream); + } + + if ($file instanceof FlysystemFile) { + $file->delete(); + } else { + $filesystem = new LocalFilesystem(); + $filesystem->remove($file->getPathname()); + } + + return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix); + } + +} diff --git a/composer.json b/composer.json index 7e123de..a5cea42 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ ], "require": { + "php":">=5.4", "symfony/framework-bundle": "^2.4.0|~3.0", "symfony/finder": "^2.4.0|~3.0", "paragonie/random_compat": "^1.1" @@ -27,11 +28,13 @@ "symfony/security-bundle": "2.*|~3.0", "sensio/framework-extra-bundle": "2.*|~3.0", "symfony/browser-kit": "2.*|~3.0", - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "~4.4", + "oneup/flysystem-bundle": "^1.2" }, "suggest": { - "knplabs/knp-gaufrette-bundle": "0.1.*" + "knplabs/knp-gaufrette-bundle": "0.1.*", + "oneup/flysystem-bundle": "^1.2" }, "autoload": {
0
e7b632698fead9ca6e15bf567aac82249bbd97c4
1up-lab/OneupUploaderBundle
Update frontend_fancyupload.md Added a note about the minimal example.
commit e7b632698fead9ca6e15bf567aac82249bbd97c4 Author: Jim Schmid <[email protected]> Date: Fri Apr 12 12:22:04 2013 +0300 Update frontend_fancyupload.md Added a note about the minimal example. diff --git a/Resources/doc/frontend_fancyupload.md b/Resources/doc/frontend_fancyupload.md index bad221a..da918c2 100644 --- a/Resources/doc/frontend_fancyupload.md +++ b/Resources/doc/frontend_fancyupload.md @@ -3,6 +3,8 @@ Use FancyUpload Download [FancyUpload](http://digitarald.de/project/fancyupload/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}` and include the FlashUploader file (`path`). +> If you have any idea on how to make a minimal example about the usage of FancyUpload, consider creating a pull-request. + ```html <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools.js"></script> @@ -103,4 +105,4 @@ oneup_uploader: frontend: fancyupload ``` -Be sure to check out the [official manual](http://digitarald.de/project/fancyupload/) for details on the configuration. \ No newline at end of file +Be sure to check out the [official manual](http://digitarald.de/project/fancyupload/) for details on the configuration.
0
68af0229f159a7d62225c5d503cbf4fa8ca7b1ca
1up-lab/OneupUploaderBundle
Added some better and more accurate on how to return errors
commit 68af0229f159a7d62225c5d503cbf4fa8ca7b1ca Author: Martin Aarhof <[email protected]> Date: Thu Dec 17 18:38:22 2015 +0100 Added some better and more accurate on how to return errors diff --git a/Resources/doc/custom_error_handler.md b/Resources/doc/custom_error_handler.md index 4110836..9fefa4c 100644 --- a/Resources/doc/custom_error_handler.md +++ b/Resources/doc/custom_error_handler.md @@ -42,4 +42,9 @@ oneup_uploader: error_handler: acme_demo.custom_error_handler ``` -**Note**: As of [9dbd905](https://github.com/1up-lab/OneupUploaderBundle/commit/9dbd9056dfe403ce6f1273d2d75fe814d517731a) only the `BlueimpErrorHandler` is implemented. If you know how to implement the error handlers for the other supported frontends, please create a pull request or drop me a note. +**Note**: + +* As of [9dbd905](https://github.com/1up-lab/OneupUploaderBundle/commit/9dbd9056dfe403ce6f1273d2d75fe814d517731a) `BlueimpErrorHandler` is implemented. +* As of [f420fff](https://github.com/1up-lab/OneupUploaderBundle/commit/f420fff5bc3ec910e925ceae15bc513b419693f2) `DropZoneErrorHandler` is implemented. + +If you know how to implement the error handlers for the other supported frontends, please create a pull request or drop me a note. diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md index 88c6d71..0a1b39a 100644 --- a/Resources/doc/custom_logic.md +++ b/Resources/doc/custom_logic.md @@ -90,3 +90,21 @@ If you are using chunked uploads and hook into the `oneup_uploader.post_chunk_up * `getType`: Get the name of the mapping of the current upload. Useful if you have multiple mappings and EventListeners. * `getConfig`: Get the config of the mapping. * `isLast`: Returns `true` if this is the last chunk to be uploaded, `false` otherwise. + +## Returning a error +You can return a upload error by throwing a ```Symfony\Component\HttpFoundation\File\Exception\UploadException``` exception + +But remember in the PostPersistEvent the file is already uploaded, so its up to you to remove the file before throwing the exception. + +You should use the [validation event](custom_validator.md) if possible, so the file does not touch your system. + +```php + +use Symfony\Component\HttpFoundation\File\Exception\UploadException; + +public function onUpload(PostPersistEvent $event) +{ + // Remember to remove the already uploaded file + throw new UploadException('Nope, I dont do files'); +} +```
0
df3d4bbffc10b268ac4ac7cb314b51399f10e031
1up-lab/OneupUploaderBundle
Revert "Revert "Update index.md"" Yes. I'm stupid. Thx git. This reverts commit 2e9a838b4f4275ff23b773806c9dcfa1d8b714de.
commit df3d4bbffc10b268ac4ac7cb314b51399f10e031 Author: Jim Schmid <[email protected]> Date: Wed Oct 23 15:30:40 2013 +0200 Revert "Revert "Update index.md"" Yes. I'm stupid. Thx git. This reverts commit 2e9a838b4f4275ff23b773806c9dcfa1d8b714de. diff --git a/Resources/doc/index.md b/Resources/doc/index.md index fe69b15..64fba4e 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -84,6 +84,10 @@ oneup_uploader: type: uploader ``` +The default directory that is used to upload files to is `web/uploads/{mapping_name}`. + +> It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you. + ### Step 4: Prepare your frontend No matter what library you choose, be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows:
0
287f50f7d157579d43684dcac7f7615ad061fcef
1up-lab/OneupUploaderBundle
Documented the usage of an orphanage.
commit 287f50f7d157579d43684dcac7f7615ad061fcef Author: Jim Schmid <[email protected]> Date: Tue Apr 9 09:53:04 2013 +0200 Documented the usage of an orphanage. diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 06d8d3b..63eb4ac 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -114,7 +114,7 @@ After installing and setting up the basic functionality of this bundle you can m some more advanced features. * [Enable chunked uploads](chunked_uploads.md) -* Using the Orphanage +* [Using the Orphanage](orphanage.md) * [Use Gaufrette as storage layer](gaufrette_storage.md) * [Include your own Namer](custom_namer.md) * [Testing this bundle](testing.md) diff --git a/Resources/doc/orphanage.md b/Resources/doc/orphanage.md new file mode 100644 index 0000000..303faae --- /dev/null +++ b/Resources/doc/orphanage.md @@ -0,0 +1,77 @@ +Using the Orphanage +=================== + +If you are providing a create-form with file uploads you can easily run into a problem if the user decides to not submit the form. You then have uploaded files that don't belong to any Entity or the like. For these use cases the OneupUploaderBundle has the possibility to use a so called `Orphanage`. + +The purpose of the `Orphanage` is to collect orphaned files until you come along and collect them or choose to clean up. To enable the `Orphanage` simply switch the `use_orphanage` property in your mapping to `true`. + +```yaml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + use_orphanage: true +``` + +As soon as you have `use_orphanage` set to true, uploaded files are not going to be moved directly to the configured directory. Instead, they will be moved to the directory specified under the `orphanage` key in the configuration. (see _Configure the Orphanage_) +They will be moved to the correct place as soon as you trigger the `uploadFiles` method on the Storage. + +## Prerequisites +The `Orphanage` will save your files based on the current SessionId. Because of that you need a running session, even if you provide an uploader for anonymous users. + +```yaml +# app/config/security.yml + +security: + firewalls: + main: + pattern: ^/ + anonymous: true +``` + +## The Controller part +Upload the files by triggering the `uploadFiles` method on the correct orphanage storage. + +```php +// src/Acme/Controller/AcmeController.php + +class AcmeController extends Controller +{ + public function storeAction() + { + $manager = $this->get('oneup_uploader.orphanage_manager')->get('gallery'); + $files = $manager->uploadFiles(); + } +} +``` + +You will get an array containing the moved files. + +> If you are using Gaufrette, these files are instances of `Gaufrette\File`, otherwise `Symfony\Component\HttpFoundation\File\File`. + +## Configure the Orphanage +You can configure the `Orphanage` by using the following configuration parameters. + +``` +oneup_uploader: + orphanage: + maxage: 86400 + directory: %kernel.cache_dir%/uploader/orphanage +``` + +You can choose a custom directory to save the orphans temporarily while uploading by changing the parameter `directory`. + +## Clean up +The `OrphanageManager` can be forced to clean up orphans by using the command provided by the OneupUploaderBundle. + + $> php app/console oneup:uploader:clean-orphans + +This parameter will clean all orphaned files older than the `maxage` value in your configuration. + +## Known Limitations +The `Orphanage` will save uploaded files in a directory like the following: + + %kernel.cache_dir%/uploader/orphanage/{session_id}/uploaded_file.ext + +It is currently not possible to change the part after `%kernel.cache_dir%/uploader/orphanage` dynamically. This has some implications. If a user will upload files through your `gallery` mapping, and choose not to submit the form, but instead start over with a new form handled by the `gallery` mapping, the newly uploaded files are going to be moved in the same directory. Therefore you will get both the files uploaded the first time and the second time if you trigger the `uploadFiles` method. \ No newline at end of file
0
1bf94c18f75f222e8f7852d45d3ecfa7798c7106
1up-lab/OneupUploaderBundle
Rename branch master to main
commit 1bf94c18f75f222e8f7852d45d3ecfa7798c7106 Author: David Greminger <[email protected]> Date: Mon Feb 5 13:14:22 2024 +0100 Rename branch master to main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c78c8b7..24eb020 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: pull_request: ~ push: branches: - - master + - main tags: - '*' diff --git a/README.md b/README.md index c59bc59..a71ab81 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ OneupUploaderBundle [![CI](https://github.com/1up-lab/OneupUploaderBundle/workflows/CI/badge.svg)](https://github.com/1up-lab/OneupUploaderBundle/actions) [![Total Downloads](https://poser.pugx.org/oneup/uploader-bundle/d/total.png)](https://packagist.org/packages/oneup/uploader-bundle) -The OneupUploaderBundle for Symfony adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_uploader.md). +The OneupUploaderBundle for Symfony adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/custom_uploader.md). * [Dropzone](http://www.dropzonejs.com/) * [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/) @@ -30,7 +30,7 @@ Documentation The entry point of the documentation can be found in the file `docs/index.md` -[Read the documentation for master](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/index.md) +[Read the documentation for main](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md) Upgrade Notes ------------- @@ -41,8 +41,8 @@ Upgrade Notes * Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). * Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57). * If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320). -* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_error_handler.md). -* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_logic.md#using-chunked-uploads). +* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/custom_error_handler.md). +* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/custom_logic.md#using-chunked-uploads). * Event names [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be) in Version **0.9.3**, update your EventListener accordingly. License diff --git a/doc/frontend_blueimp.md b/doc/frontend_blueimp.md index db30fdf..86ba4ef 100644 --- a/doc/frontend_blueimp.md +++ b/doc/frontend_blueimp.md @@ -46,7 +46,7 @@ security: Next steps ---------- -After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps). * [Process uploaded files using custom logic](custom_logic.md) * [Return custom data to frontend](response.md) diff --git a/doc/frontend_dropzone.md b/doc/frontend_dropzone.md index c6b2c64..e1cb572 100644 --- a/doc/frontend_dropzone.md +++ b/doc/frontend_dropzone.md @@ -26,7 +26,7 @@ Be sure to check out the [official manual](http://www.dropzonejs.com/) for detai Next steps ---------- -After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps). * [Process uploaded files using custom logic](custom_logic.md) * [Return custom data to frontend](response.md) diff --git a/doc/frontend_fancyupload.md b/doc/frontend_fancyupload.md index 09896f0..5cf7bb5 100644 --- a/doc/frontend_fancyupload.md +++ b/doc/frontend_fancyupload.md @@ -110,7 +110,7 @@ Be sure to check out the [official manual](http://digitarald.de/project/fancyupl Next steps ---------- -After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps). * [Process uploaded files using custom logic](custom_logic.md) * [Return custom data to frontend](response.md) diff --git a/doc/frontend_fineuploader.md b/doc/frontend_fineuploader.md index 8519f97..0976de5 100644 --- a/doc/frontend_fineuploader.md +++ b/doc/frontend_fineuploader.md @@ -38,7 +38,7 @@ Be sure to check out the [official manual](https://github.com/FineUploader/fine- Next steps ---------- -After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps). * [Process uploaded files using custom logic](custom_logic.md) * [Return custom data to frontend](response.md) diff --git a/doc/frontend_mooupload.md b/doc/frontend_mooupload.md index 6a1db2c..68e1ac0 100644 --- a/doc/frontend_mooupload.md +++ b/doc/frontend_mooupload.md @@ -37,7 +37,7 @@ Be sure to check out the [official manual](https://github.com/juanparati/MooUplo Next steps ---------- -After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps). * [Process uploaded files using custom logic](custom_logic.md) * [Return custom data to frontend](response.md) diff --git a/doc/frontend_plupload.md b/doc/frontend_plupload.md index 0c2e01d..3dac128 100644 --- a/doc/frontend_plupload.md +++ b/doc/frontend_plupload.md @@ -52,7 +52,7 @@ security: Next steps ---------- -After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps). * [Process uploaded files using custom logic](custom_logic.md) * [Return custom data to frontend](response.md) diff --git a/doc/frontend_uploadify.md b/doc/frontend_uploadify.md index ec7bcc9..0e005d9 100644 --- a/doc/frontend_uploadify.md +++ b/doc/frontend_uploadify.md @@ -39,7 +39,7 @@ Be sure to check out the [official manual](http://www.uploadify.com/documentatio Next steps ---------- -After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps). * [Process uploaded files using custom logic](custom_logic.md) * [Return custom data to frontend](response.md)
0
17d29a05616aaabc0cc572fd6e110b75f4644631
1up-lab/OneupUploaderBundle
Added FAQ section to index.md
commit 17d29a05616aaabc0cc572fd6e110b75f4644631 Author: Jim Schmid <[email protected]> Date: Tue Apr 9 10:52:27 2013 +0200 Added FAQ section to index.md diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 5688e52..bceea87 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -121,3 +121,9 @@ some more advanced features. * [Include your own Namer](custom_namer.md) * [Testing this bundle](testing.md) * [Configuration Reference](configuration_reference.md) + +## FAQ + +> Why didn't you implement the _delete_ feature provided by Fine Uploader? + +Fine Uploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](https://github.com/Widen/fine-uploader/blob/master/docs/options-fineuploaderbasic.md#deletefile-option-properties) and on [the blog](http://blog.fineuploader.com/2013/01/delete-uploaded-file-in-33.html) of Fine Uploader. \ No newline at end of file
0
d487c82c266da721c790f82a0e3bf2a09a018354
1up-lab/OneupUploaderBundle
Ordered JavaScript libraries by today's relevance Please update this in the project's discription too: This Symfony2 bundle provides a server implementation for handling single and multiple file uploads using either FineUploader, jQuery File Uploader, YUI3 Uploader, Uploadify, FancyUpload, MooUpload, Plupload or Dropzone. Features include chunked uploads, orphanages and Gaufrette support. I would even go further and mark the MooTools & YUI libraries as deprecated.
commit d487c82c266da721c790f82a0e3bf2a09a018354 Author: Thomas Landauer <[email protected]> Date: Sun Oct 25 16:41:01 2015 +0100 Ordered JavaScript libraries by today's relevance Please update this in the project's discription too: This Symfony2 bundle provides a server implementation for handling single and multiple file uploads using either FineUploader, jQuery File Uploader, YUI3 Uploader, Uploadify, FancyUpload, MooUpload, Plupload or Dropzone. Features include chunked uploads, orphanages and Gaufrette support. I would even go further and mark the MooTools & YUI libraries as deprecated. diff --git a/README.md b/README.md index daa5eac..b6b3992 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,17 @@ OneupUploaderBundle =================== -The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following Javascript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md). +The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md). -* [FineUploader](http://fineuploader.com/) -* [jQuery File Uploader](http://blueimp.github.io/jQuery-File-Upload/) -* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/) -* [Uploadify](http://www.uploadify.com/) -* [FancyUpload](http://digitarald.de/project/fancyupload/) -* [MooUpload](https://github.com/juanparati/MooUpload) -* [Plupload](http://www.plupload.com/) +* [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/) * [Dropzone](http://www.dropzonejs.com/) +* [Plupload](http://www.plupload.com/) +* [FineUploader](http://fineuploader.com/) +* [FancyUpload](http://digitarald.de/project/fancyupload/) (based on MooTools) +* [MooUpload](https://github.com/juanparati/MooUpload) (based on MooTools) +* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/) (the YUI library is no longer maintained) +* [UploadiFive](http://www.uploadify.com/) ($ 5.00) + Features included:
0
1589bd69468c1734bb20337bfbdb00c455b8d868
1up-lab/OneupUploaderBundle
Run phpstan on max level
commit 1589bd69468c1734bb20337bfbdb00c455b8d868 Author: David Greminger <[email protected]> Date: Fri Oct 23 11:58:17 2020 +0200 Run phpstan on max level diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26eb666..7605e04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: - name: Check the coding style run: vendor/bin/php-cs-fixer fix --diff --dry-run - name: Analyze the code - run: vendor/bin/phpstan analyze src/ tests/ --level=6 + run: vendor/bin/phpstan analyze src/ tests/ --level=max tests: name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }} diff --git a/phpstan.neon b/phpstan.neon index bb9931f..b945375 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ parameters: - bootstrap: %rootDir%/../../../vendor/autoload.php + bootstrapFiles: + - %rootDir%/../../../vendor/autoload.php excludes_analyse: - src/DependencyInjection/Configuration.php diff --git a/tests/Controller/AbstractControllerTest.php b/tests/Controller/AbstractControllerTest.php index 194ec28..90f84db 100644 --- a/tests/Controller/AbstractControllerTest.php +++ b/tests/Controller/AbstractControllerTest.php @@ -140,7 +140,7 @@ abstract class AbstractControllerTest extends WebTestCase $response = $client->getResponse(); $this->assertSame($expectedStatusCode, $response->getStatusCode()); - $this->assertStringContainsStringIgnoringCase($expectedContentType, $response->headers->get('Content-Type')); + $this->assertStringContainsStringIgnoringCase($expectedContentType, (string) $response->headers->get('Content-Type')); } protected function createTempFile(int $size = 128): string
0
586ef1bb5c13a2bafc4d3fd1b428a1a7cf93a6d7
1up-lab/OneupUploaderBundle
Introduced orphanage you can use for uploads which must be picked up manually.
commit 586ef1bb5c13a2bafc4d3fd1b428a1a7cf93a6d7 Author: Jim Schmid <[email protected]> Date: Tue Mar 12 11:12:19 2013 +0100 Introduced orphanage you can use for uploads which must be picked up manually. diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 7900b4e..6e820db 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -28,6 +28,13 @@ class Configuration implements ConfigurationInterface ->scalarNode('maxage')->defaultValue(604800)->end() ->end() ->end() + ->arrayNode('orphanage') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('directory')->end() + ->scalarNode('maxage')->defaultValue(604800)->end() + ->end() + ->end() ->arrayNode('mappings') ->useAttributeAsKey('id') ->isRequired() @@ -35,6 +42,7 @@ class Configuration implements ConfigurationInterface ->prototype('array') ->children() ->scalarNode('storage')->isRequired()->end() + ->scalarNode('use_orphanage')->defaultFalse()->end() ->scalarNode('action')->defaultNull()->end() ->scalarNode('namer')->defaultNull()->end() ->end() diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 0762b91..01ca0b3 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -26,11 +26,19 @@ class OneupUploaderExtension extends Extension // handling chunk configuration if(!array_key_exists('directory', $config['chunks'])) { - $config['chunks']['directory'] = sprintf('%s/chunks', $container->getParameter('kernel.cache_dir')); + $config['chunks']['directory'] = sprintf('%s/uploader/chunks', $container->getParameter('kernel.cache_dir')); } $container->setParameter('oneup_uploader.chunks', $config['chunks']); + // handling orphanage configuration + if(!array_key_exists('directory', $config['orphanage'])) + { + $config['orphanage']['directory'] = sprintf('%s/uploader/orphanage', $container->getParameter('kernel.cache_dir')); + } + + $container->setParameter('oneup_uploader.orphanage', $config['orphanage']); + // handle mappings foreach($config['mappings'] as $key => $mapping) {
0
161a0e266ad222c1adc0d399c553a138386bb23e
1up-lab/OneupUploaderBundle
Added Validation test for FineUploader.
commit 161a0e266ad222c1adc0d399c553a138386bb23e Author: Jim Schmid <[email protected]> Date: Sat May 18 16:58:29 2013 +0200 Added Validation test for FineUploader. diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index fcb884e..2c577af 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -28,6 +28,15 @@ oneup_uploader: frontend: fineuploader storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload + + fineuploader_validation: + frontend: fineuploader + storage: + directory: %kernel.root_dir%/cache/%kernel.environment%/upload + allowed_extensions: [ "ok" ] + disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] + disallowed_mimetypes: [ "image/gif" ] fancyupload: frontend: fancyupload diff --git a/Tests/Controller/FineUploaderValidationTest.php b/Tests/Controller/FineUploaderValidationTest.php new file mode 100644 index 0000000..32586b3 --- /dev/null +++ b/Tests/Controller/FineUploaderValidationTest.php @@ -0,0 +1,59 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Controller; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest; + +class FineUploaderValidationTest extends AbstractValidationTest +{ + protected function getConfigKey() + { + return 'fineuploader_validation'; + } + + protected function getRequestParameters() + { + return array(); + } + + protected function getFileWithCorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'text/plain', + 128 + ); + } + + protected function getFileWithIncorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.fail', + 'text/plain', + 128 + ); + } + + protected function getFileWithCorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/jpg', + 128 + ); + } + + protected function getFileWithIncorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/gif', + 128 + ); + } +}
0
550578a4b03a3fb819633a039b78d2c20eb2287f
1up-lab/OneupUploaderBundle
Merge pull request #216 from JHGitty/patch-2 Improve custom namer doc
commit 550578a4b03a3fb819633a039b78d2c20eb2287f (from 8be7573e9178b30d27f947967b86ee029654aa68) Merge: 8be7573 8279b7e Author: Jim Schmid <[email protected]> Date: Mon Feb 8 08:35:16 2016 +0100 Merge pull request #216 from JHGitty/patch-2 Improve custom namer doc diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md index 0d9dc17..256d2c6 100644 --- a/Resources/doc/custom_namer.md +++ b/Resources/doc/custom_namer.md @@ -10,7 +10,7 @@ First, create a custom namer which implements ```Oneup\UploaderBundle\Uploader\N ```php <?php -namespace Acme\DemoBundle; +namespace AppBundle\Uploader\Naming; use Oneup\UploaderBundle\Uploader\File\FileInterface; use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; @@ -36,8 +36,8 @@ Next, register your created namer as a service in your `services.xml` ```yml services: - acme_demo.custom_namer: - class: Acme\DemoBundle\CatNamer + app.cat_namer: + class: AppBundle\Uploader\Naming\CatNamer ``` Now you can use your custom service by adding it to your configuration: @@ -46,7 +46,7 @@ Now you can use your custom service by adding it to your configuration: oneup_uploader: mappings: gallery: - namer: acme_demo.custom_namer + namer: app.cat_namer ``` Every file uploaded through the `Controller` of this mapping will be named with your custom namer. commit 550578a4b03a3fb819633a039b78d2c20eb2287f (from 8279b7e418340ee66d4f625ab1f1d485415dec60) Merge: 8be7573 8279b7e Author: Jim Schmid <[email protected]> Date: Mon Feb 8 08:35:16 2016 +0100 Merge pull request #216 from JHGitty/patch-2 Improve custom namer doc diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index fd6d87a..c577309 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -1,7 +1,7 @@ Using Chunked Uploads ===================== -Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. +Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabled, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. ```js $(document).ready(function() diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md index bc4240f..256d2c6 100644 --- a/Resources/doc/custom_namer.md +++ b/Resources/doc/custom_namer.md @@ -24,7 +24,7 @@ class CatNamer implements NamerInterface } ``` -To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. +To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. The namer should return an unique name to avoid issues if the file already exists. Next, register your created namer as a service in your `services.xml` diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md index cd8a019..22fbb16 100644 --- a/Resources/doc/frontend_fineuploader.md +++ b/Resources/doc/frontend_fineuploader.md @@ -1,26 +1,27 @@ Use FineUploader ================ -Download [FineUploader](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. +Download [FineUploader 5](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. This example is based on the [UI Mode](http://docs.fineuploader.com/branch/master/quickstart/01-getting-started.html) of FineUploader. ```html -<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> -<script type="text/javascript" src="js/jquery.fineuploader-3.4.1.js"></script> +<link href="fine-uploader/fine-uploader-new.min.css" rel="stylesheet"> +<script type="text/javascript" src="fine-uploader/fine-uploader.min.js"></script> <script type="text/javascript"> -$(document).ready(function() -{ var uploader = new qq.FineUploader({ - element: $('#uploader')[0], + element: document.getElementById('fine-uploader'), request: { endpoint: "{{ oneup_uploader_endpoint('gallery') }}" } }); -}); </script> -<div id="uploader"></div> +<div id="fine-uploader"></div> ``` +You can find a fully example of all available settings on the [official documentation](http://docs.fineuploader.com/branch/master/quickstart/02-setting_options.html). + +If you are using Fine Uploader UI, as described in this example, you **MUST** include a template in your document/markup. You can use the ``default.html`` file in the templates directory bundled with the FineUploader library and customize it as desired. You even can use an inline template. See the official [styling documentation page](http://docs.fineuploader.com/branch/master/features/styling.html) for more details. + Configure the OneupUploaderBundle to use the correct controller: ```yaml diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 4178e9e..39ab715 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -34,19 +34,9 @@ Perform the following steps to install and use the basic functionality of the On Add OneupUploaderBundle to your composer.json using the following construct: -```js -{ - "require": { - "oneup/uploader-bundle": "~1.4" - } -} -``` - -Now tell composer to download the bundle by running the following command: - - $> php composer.phar update oneup/uploader-bundle + $ composer require oneup/uploader-bundle "~1.4" -Composer will now fetch and install this bundle in the vendor directory ```vendor/oneup``` +Composer will install the bundle to your project's ``vendor/oneup/uploader-bundle`` directory. ### Step 2: Enable the bundle
0
2e9a838b4f4275ff23b773806c9dcfa1d8b714de
1up-lab/OneupUploaderBundle
Revert "Update index.md" This reverts commit 4f98131894c0aca5daa067e382469204c406de76.
commit 2e9a838b4f4275ff23b773806c9dcfa1d8b714de Author: Jim Schmid <[email protected]> Date: Wed Oct 23 15:25:57 2013 +0200 Revert "Update index.md" This reverts commit 4f98131894c0aca5daa067e382469204c406de76. diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 64fba4e..fe69b15 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -84,10 +84,6 @@ oneup_uploader: type: uploader ``` -The default directory that is used to upload files to is `web/uploads/{mapping_name}`. - -> It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you. - ### Step 4: Prepare your frontend No matter what library you choose, be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows:
0
5ff6a2e7bc9c7361fc719321f2fe3d620d9c7f8a
1up-lab/OneupUploaderBundle
Merge branch 'snarktooth-flysystem-path-fix'
commit 5ff6a2e7bc9c7361fc719321f2fe3d620d9c7f8a (from 1f6fa09ab087d125bbb62204d0ccc00da5369f5d) Merge: 1f6fa09 8a922f6 Author: David Greminger <[email protected]> Date: Tue Sep 19 11:38:39 2017 +0200 Merge branch 'snarktooth-flysystem-path-fix' diff --git a/Tests/Uploader/Storage/FlysystemStorageTest.php b/Tests/Uploader/Storage/FlysystemStorageTest.php index bdd43e9..121a7ec 100644 --- a/Tests/Uploader/Storage/FlysystemStorageTest.php +++ b/Tests/Uploader/Storage/FlysystemStorageTest.php @@ -53,6 +53,22 @@ class FlysystemStorageTest extends \PHPUnit_Framework_TestCase } } + public function testUploadWithPath() + { + $payload = new FilesystemFile(new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true)); + $this->storage->upload($payload, 'notsogrumpyanymore.jpeg', 'cat'); + + $finder = new Finder(); + $finder->in($this->directory)->files(); + + $this->assertCount(1, $finder); + + foreach ($finder as $file) { + $this->assertEquals($file->getFilename(), 'notsogrumpyanymore.jpeg'); + $this->assertEquals($file->getSize(), 1024); + } + } + public function tearDown() { $filesystem = new Filesystem(); diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php index aa2fa61..08e6206 100644 --- a/Uploader/Storage/FlysystemStorage.php +++ b/Uploader/Storage/FlysystemStorage.php @@ -45,7 +45,7 @@ class FlysystemStorage implements StorageInterface } $stream = fopen($file->getPathname(), 'r+'); - $this->filesystem->putStream($name, $stream, array( + $this->filesystem->putStream($path, $stream, array( 'mimetype' => $file->getMimeType() )); if (is_resource($stream)) {
0
9917cd6f83007c5ee8e8366ce25b8467029df01c
1up-lab/OneupUploaderBundle
Using default error_handler related to frontend Till now NoopErrorHandler was used as default for any frontend Therefore for use bultin BlueimpErrorHandler for example we have to manually configure it
commit 9917cd6f83007c5ee8e8366ce25b8467029df01c Author: Veniamin Albaev <[email protected]> Date: Sun Aug 11 00:22:29 2013 +0400 Using default error_handler related to frontend Till now NoopErrorHandler was used as default for any frontend Therefore for use bultin BlueimpErrorHandler for example we have to manually configure it diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6472e05..1c8ec39 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -72,7 +72,7 @@ class Configuration implements ConfigurationInterface ->arrayNode('disallowed_mimetypes') ->prototype('scalar')->end() ->end() - ->scalarNode('error_handler')->defaultValue('oneup_uploader.error_handler.noop')->end() + ->scalarNode('error_handler')->defaultNull()->end() ->scalarNode('max_size') ->defaultValue(\PHP_INT_MAX) ->info('Set max_size to -1 for gracefully downgrade this number to the systems max upload size.') diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index fa4cb90..fae9056 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -121,7 +121,9 @@ class OneupUploaderExtension extends Extension throw new ServiceNotFoundException('Empty controller class or name. If you really want to use a custom frontend implementation, be sure to provide a class and a name.'); } - $errorHandler = new Reference($mapping['error_handler']); + $errorHandler = is_null($mapping['error_handler']) ? + new Reference('oneup_uploader.error_handler.'.$mapping['frontend']) : + new Reference($mapping['error_handler']); // create controllers based on mapping $container diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml index 025e38a..7bfb131 100644 --- a/Resources/config/errorhandler.xml +++ b/Resources/config/errorhandler.xml @@ -10,7 +10,14 @@ <services> <service id="oneup_uploader.error_handler.noop" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.fineuploader" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false" /> + <service id="oneup_uploader.error_handler.uploadify" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.yui3" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.mooupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> + <service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" /> </services> </container>
0
533bea2b5f8a5609075d7312fe83a1523ae0e110
1up-lab/OneupUploaderBundle
Added new configuration values to the reference documentation.
commit 533bea2b5f8a5609075d7312fe83a1523ae0e110 Author: Jim Schmid <[email protected]> Date: Thu Apr 18 19:02:25 2013 +0200 Added new configuration values to the reference documentation. diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index 65cf43c..51bd42d 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -11,10 +11,15 @@ oneup_uploader: orphanage: maxage: 604800 directory: ~ + twig: true mappings: # Required # Prototype id: + frontend: fineuploader + custom_frontend: + name: ~ + class: ~ storage: service: ~ type: filesystem
0
913046018e89163c3c04756baa48b3eed12454b1
1up-lab/OneupUploaderBundle
Updated cs fixer
commit 913046018e89163c3c04756baa48b3eed12454b1 Author: David Greminger <[email protected]> Date: Fri Oct 23 11:47:27 2020 +0200 Updated cs fixer diff --git a/.php_cs.dist b/.php_cs.dist index 3f15c9a..428e683 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -7,11 +7,13 @@ $finder = PhpCsFixer\Finder::create() return PhpCsFixer\Config::create() ->setRules([ + '@DoctrineAnnotation' => true, '@Symfony' => true, '@Symfony:risky' => true, '@PHP71Migration' => true, '@PHP71Migration:risky' => true, '@PHPUnit60Migration:risky' => true, + '@PHPUnit75Migration:risky' => true, 'align_multiline_comment' => true, 'array_syntax' => ['syntax' => 'short'], 'concat_space' => [ diff --git a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php index 53f2071..3a5e734 100644 --- a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php +++ b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php @@ -113,7 +113,7 @@ class GaufretteOrphanageStorageTest extends OrphanageTest $files = $this->orphanage->uploadFiles(); - $this->assertInternalType('array', $files); + $this->assertIsArray($files); $this->assertCount($this->numberOfPayloads, $files); $finder = new Finder();
0
0abea705145a0943144f0eebf99ebcc6373d3da9
1up-lab/OneupUploaderBundle
Added Travis CI integration.
commit 0abea705145a0943144f0eebf99ebcc6373d3da9 Author: Jim Schmid <[email protected]> Date: Fri Mar 8 18:56:55 2013 +0100 Added Travis CI integration. diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..bec17da --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: php + +php: + - 5.3 + - 5.4 \ No newline at end of file
0
645d01718a7af9815baa95d1c2209bf08f43a4bd
1up-lab/OneupUploaderBundle
Fix typo.
commit 645d01718a7af9815baa95d1c2209bf08f43a4bd Author: David Greminger <[email protected]> Date: Wed May 18 13:03:49 2016 +0200 Fix typo. diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 39ab715..5fd3425 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -25,7 +25,7 @@ framework: Perform the following steps to install and use the basic functionality of the OneupUploaderBundle: -* Download OnueupUploaderBundle using Composer +* Download OneupUploaderBundle using Composer * Enable the bundle * Configure the bundle * Prepare your frontend
0
99deda33158bd6279b3af4f488007a6541be4ad1
1up-lab/OneupUploaderBundle
Added function comments for AbstractChunkedController.
commit 99deda33158bd6279b3af4f488007a6541be4ad1 Author: Jim Schmid <[email protected]> Date: Fri May 31 18:14:54 2013 +0200 Added function comments for AbstractChunkedController. diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php index f32cc56..3bd1247 100644 --- a/Controller/AbstractChunkedController.php +++ b/Controller/AbstractChunkedController.php @@ -8,8 +8,33 @@ use Oneup\UploaderBundle\Controller\AbstractController; abstract class AbstractChunkedController extends AbstractController { + /** + * Parses a chunked request and return relevant information. + * + * This function must return an array containing the following + * keys and their corresponding values: + * - last: Wheter this is the last chunk of the uploaded file + * - uuid: A unique id which distinguishes two uploaded files + * This uuid must stay the same among the task of + * uploading a chunked file. + * - index: A numerical representation of the currently uploaded + * chunk. Must be higher that in the previous request. + * - orig: The original file name. + * + * @param request The request object + */ abstract protected function parseChunkedRequest(Request $request); + /** + * This function will be called in order to upload and save an + * uploaded chunk. + * + * This function also calls the chunk manager if the function + * parseChunkedRequest has set true for the "last" key of the + * returned array. + * + * @param file The uploaded chunk. + */ protected function handleChunkedUpload(UploadedFile $file) { // get basic container stuff
0
d161b18bf148228c70d730d40def3125f667a94b
1up-lab/OneupUploaderBundle
Testing existance of moved files as well as clean up afterwards.
commit d161b18bf148228c70d730d40def3125f667a94b Author: Jim Schmid <[email protected]> Date: Sat Apr 6 16:07:58 2013 +0200 Testing existance of moved files as well as clean up afterwards. diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index 567d066..bf433f9 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -2,6 +2,8 @@ namespace Oneup\UploaderBundle\Tests\Controller; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer; @@ -35,10 +37,20 @@ class ControllerTest extends \PHPUnit_Framework_TestCase ); $controller = new UploaderController($container, $storage, $config, 'cat'); - $controller->upload(); + $response = $controller->upload(); // check if original file has been moved $this->assertFalse(file_exists($this->tempFile)); + + // testing response + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + + // check if file is present + $finder = new Finder(); + $finder->in(sys_get_temp_dir() . '/uploader')->files(); + + $this->assertCount(1, $finder); } protected function getContainerMock() @@ -98,4 +110,11 @@ class ControllerTest extends \PHPUnit_Framework_TestCase { return new UploadedFile($this->tempFile, 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true); } + + public function tearDown() + { + // remove all files in tmp folder + $filesystem = new Filesystem(); + $filesystem->remove(sys_get_temp_dir() . '/uploader'); + } } \ No newline at end of file
0
a6df30d55b6c8c2672d29d638e5913edfe4a1f4e
1up-lab/OneupUploaderBundle
Refactored validation system to use the EventDispatcher.
commit a6df30d55b6c8c2672d29d638e5913edfe4a1f4e Author: Jim Schmid <[email protected]> Date: Mon Apr 22 18:49:24 2013 +0200 Refactored validation system to use the EventDispatcher. diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index ac8a1f0..23fb699 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Request; use Oneup\UploaderBundle\UploadEvents; use Oneup\UploaderBundle\Event\PostPersistEvent; use Oneup\UploaderBundle\Event\PostUploadEvent; +use Oneup\UploaderBundle\Event\ValidationEvent; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; @@ -66,21 +67,17 @@ abstract class AbstractController protected function validate(UploadedFile $file) { - // check if the file size submited by the client is over the max size in our config - if($file->getClientSize() > $this->config['max_size']) - throw new UploadException('error.maxsize'); - - $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); - - // if this mapping defines at least one type of an allowed extension, - // test if the current is in this array - if(count($this->config['allowed_extensions']) > 0 && !in_array($extension, $this->config['allowed_extensions'])) - throw new UploadException('error.whitelist'); - - // check if the current extension is mentioned in the disallowed types - // and if so, throw an exception - if(count($this->config['disallowed_extensions']) > 0 && in_array($extension, $this->config['disallowed_extensions'])) - throw new UploadException('error.blacklist'); + $dispatcher = $this->container->get('event_dispatcher'); + $event = new ValidationEvent($file, $this->config, $this->type); + try + { + $dispatcher->dispatch(UploadEvents::VALIDATION, $event); + } + catch(ValidationException $exception) + { + // pass the exception one level up + throw new UploadException($exception->getMessage()); + } } } diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php new file mode 100644 index 0000000..5fd4d98 --- /dev/null +++ b/Event/ValidationEvent.php @@ -0,0 +1,34 @@ +<?php + +namespace Oneup\UploaderBundle\Event; + +use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\HttpFoundation\File\UploadedFile; + +class ValidationEvent extends Event +{ + protected $file; + protected $config; + + public function __construct(UploadedFile $file, array $config, $type) + { + $this->file = $file; + $this->config = $config; + $this->type = $type; + } + + public function getFile() + { + return $this->file; + } + + public function getConfig() + { + return $this->config; + } + + public function getType() + { + return $this->type; + } +} diff --git a/UploadEvents.php b/UploadEvents.php index 34e287c..8bec67f 100644 --- a/UploadEvents.php +++ b/UploadEvents.php @@ -6,4 +6,5 @@ final class UploadEvents { const POST_PERSIST = 'oneup_uploader.post_persist'; const POST_UPLOAD = 'oneup_uploader.post_upload'; + const VALIDATION = 'oneup_uploader.validate'; } \ No newline at end of file
0
94833f3445e73121dab0ae1aac4a5ec7f6fb16fc
1up-lab/OneupUploaderBundle
Makes BlueimpController selectable through configuration.
commit 94833f3445e73121dab0ae1aac4a5ec7f6fb16fc Author: Jim Schmid <[email protected]> Date: Tue Apr 9 21:07:42 2013 +0200 Makes BlueimpController selectable through configuration. diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0ae1d2e..8848e0d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -35,7 +35,7 @@ class Configuration implements ConfigurationInterface ->prototype('array') ->children() ->enumNode('frontend') - ->values(array('fineuploader', 'reserved')) + ->values(array('fineuploader', 'blueimp')) ->defaultValue('fineuploader') ->end() ->arrayNode('storage') diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index ad48473..7083edf 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -12,6 +12,7 @@ <parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Storage\OrphanageStorage</parameter> <parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter> <parameter key="oneup_uploader.controller.fineuploader.class">Oneup\UploaderBundle\Controller\FineUploaderController</parameter> + <parameter key="oneup_uploader.controller.blueimp.class">Oneup\UploaderBundle\Controller\BlueimpController</parameter> </parameters> <services>
0
9a001b8806b83cf46e5ed84bd44db023e331103d
1up-lab/OneupUploaderBundle
Added missing methods to OrphanageInterface.
commit 9a001b8806b83cf46e5ed84bd44db023e331103d Author: Jim Schmid <[email protected]> Date: Thu Mar 14 17:18:18 2013 +0100 Added missing methods to OrphanageInterface. diff --git a/Uploader/Orphanage/OrphanageInterface.php b/Uploader/Orphanage/OrphanageInterface.php index 8e75e4e..00b584a 100644 --- a/Uploader/Orphanage/OrphanageInterface.php +++ b/Uploader/Orphanage/OrphanageInterface.php @@ -7,4 +7,5 @@ use Symfony\Component\HttpFoundation\File\File; interface OrphanageInterface { public function addFile(File $file, $name); + public function uploadFiles($keep = false); }
0
dd1639c6edfd893e4878163cd72b48333264298a
1up-lab/OneupUploaderBundle
Added frontend_fancyupload.md to the correct directory
commit dd1639c6edfd893e4878163cd72b48333264298a Author: Jim Schmid <[email protected]> Date: Thu Apr 11 22:44:13 2013 +0200 Added frontend_fancyupload.md to the correct directory diff --git a/Resources/config/frontend_fancyupload.md b/Resources/doc/frontend_fancyupload.md similarity index 100% rename from Resources/config/frontend_fancyupload.md rename to Resources/doc/frontend_fancyupload.md diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 6cd7a2c..663f91e 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -94,6 +94,7 @@ So if you take the mapping described before, the generated route name would be ` * [Use jQuery File Upload](frontend_blueimp.md) * [Use YUI3 Uploader](frontend_yui3.md) * [Use Uploadify](frontend_uploadify.md) +* [Use FancyUpload](frontend_fancyupload.md) This is of course a very minimal setup. Be sure to include stylesheets for Fine Uploader if you want to use them.
0
460b24323e1ef5f7dd7ef8088a7bcb5e76959b52
1up-lab/OneupUploaderBundle
Removed die(). Whoopsi.
commit 460b24323e1ef5f7dd7ef8088a7bcb5e76959b52 Author: Jim Schmid <[email protected]> Date: Sat Apr 6 10:25:11 2013 +0200 Removed die(). Whoopsi. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index dc1e83c..3e63f8b 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -102,7 +102,7 @@ class UploaderController implements UploadControllerInterface // we'll take the first chunk and append the others to it // this way we don't need another file in temporary space for assembling $chunks = $chunkManager->getChunks($uuid); - die(); + // assemble parts $assembled = $chunkManager->assembleChunks($chunks); $path = $assembled->getPath();
0
60b054aece831b7739c7ea7cd942eb01cc610576
1up-lab/OneupUploaderBundle
Prevent key normalization
commit 60b054aece831b7739c7ea7cd942eb01cc610576 Author: Jérôme Parmentier <[email protected]> Date: Fri Sep 22 14:58:25 2017 +0200 Prevent key normalization diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a6f3b2b..a26cdde 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -76,6 +76,7 @@ class Configuration implements ConfigurationInterface ->end() ->scalarNode('route_prefix')->defaultValue('')->end() ->arrayNode('allowed_mimetypes') + ->normalizeKeys(false) ->useAttributeAsKey('type') ->prototype('array') ->prototype('scalar')
0
5959952f2f6f9765122781110d7201ac2623f981
1up-lab/OneupUploaderBundle
CS fixes for the rest.
commit 5959952f2f6f9765122781110d7201ac2623f981 Author: Jim Schmid <[email protected]> Date: Thu Jun 20 21:25:52 2013 +0200 CS fixes for the rest. diff --git a/Resources/config/templating.xml b/Resources/config/templating.xml index 4593804..a964783 100644 --- a/Resources/config/templating.xml +++ b/Resources/config/templating.xml @@ -13,4 +13,4 @@ </services> -</container> \ No newline at end of file +</container> diff --git a/Resources/config/twig.xml b/Resources/config/twig.xml index 95c0c2d..31f68e1 100644 --- a/Resources/config/twig.xml +++ b/Resources/config/twig.xml @@ -13,4 +13,4 @@ </services> -</container> \ No newline at end of file +</container> diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 49de680..f6c93af 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -21,26 +21,26 @@ </parameters> <services> - + <!-- managers --> <service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%"> <argument>%oneup_uploader.chunks%</argument> </service> - + <service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%"> <argument type="service" id="service_container" /> <argument>%oneup_uploader.orphanage%</argument> </service> - + <!-- namer --> <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" /> - + <!-- routing --> <service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%"> <argument>%oneup_uploader.controllers%</argument> <tag name="routing.loader" /> </service> - + </services> -</container> \ No newline at end of file +</container> diff --git a/Resources/config/validators.xml b/Resources/config/validators.xml index a47e6a9..8f435c5 100644 --- a/Resources/config/validators.xml +++ b/Resources/config/validators.xml @@ -15,11 +15,11 @@ <service id="oneup_uploader.validation_listener.disallowed_extension" class="Oneup\UploaderBundle\EventListener\DisallowedExtensionValidationListener"> <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> </service> - + <service id="oneup_uploader.validation_listener.allowed_mimetype" class="Oneup\UploaderBundle\EventListener\AllowedMimetypeValidationListener"> <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> </service> - + <service id="oneup_uploader.validation_listener.disallowed_mimetype" class="Oneup\UploaderBundle\EventListener\DisallowedMimetypeValidationListener"> <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> </service> diff --git a/Resources/translations/OneupUploaderBundle.en.yml b/Resources/translations/OneupUploaderBundle.en.yml index 4d5f620..6f38377 100644 --- a/Resources/translations/OneupUploaderBundle.en.yml +++ b/Resources/translations/OneupUploaderBundle.en.yml @@ -1,4 +1,4 @@ error: maxsize: This file is too large. whitelist: This file type is not allowed. - blacklist: This file type is not allowed. \ No newline at end of file + blacklist: This file type is not allowed. diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php index 9145ff1..236f950 100644 --- a/Routing/RouteLoader.php +++ b/Routing/RouteLoader.php @@ -9,32 +9,31 @@ use Symfony\Component\Routing\RouteCollection; class RouteLoader extends Loader { protected $controllers; - + public function __construct(array $controllers) { $this->controllers = $controllers; } - + public function supports($resource, $type = null) { return $type === 'uploader'; } - + public function load($resource, $type = null) { $routes = new RouteCollection(); - - foreach($this->controllers as $type => $service) - { + + foreach ($this->controllers as $type => $service) { $upload = new Route( sprintf('/_uploader/%s/upload', $type), array('_controller' => $service . ':upload', '_format' => 'json'), array('_method' => 'POST') ); - + $routes->add(sprintf('_uploader_%s', $type), $upload); } - + return $routes; } -} \ No newline at end of file +} diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php index b5c376a..1882766 100644 --- a/Templating/Helper/UploaderHelper.php +++ b/Templating/Helper/UploaderHelper.php @@ -8,19 +8,19 @@ use Symfony\Component\Templating\Helper\Helper; class UploaderHelper extends Helper { protected $router; - + public function __construct(RouterInterface $router) { $this->router = $router; } - + public function getName() { return 'oneup_uploader'; } - + public function endpoint($key) { return $this->router->generate(sprintf('_uploader_%s', $key)); } -} \ No newline at end of file +} diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php index 910a0f9..8849b79 100644 --- a/Twig/Extension/UploaderExtension.php +++ b/Twig/Extension/UploaderExtension.php @@ -7,24 +7,24 @@ use Oneup\UploaderBundle\Templating\Helper\UploaderHelper; class UploaderExtension extends \Twig_Extension { protected $helper; - + public function __construct(UploaderHelper $helper) { $this->helper = $helper; } - + public function getName() { return 'oneup_uploader'; } - + public function getFunctions() { return array('oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint')); } - + public function endpoint($key) { return $this->helper->endpoint($key); } -} \ No newline at end of file +}
0
d22c230f85f036f5c68f038eb25f577da0b60ee0
1up-lab/OneupUploaderBundle
Introduced UploaderResponse. You are now able to add custom data to the output, even from EventListener.
commit d22c230f85f036f5c68f038eb25f577da0b60ee0 Author: Jim Schmid <[email protected]> Date: Thu Mar 28 15:05:35 2013 +0100 Introduced UploaderResponse. You are now able to add custom data to the output, even from EventListener. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index f29fff7..465b264 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -17,6 +17,7 @@ use Oneup\UploaderBundle\Controller\UploadControllerInterface; use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface; +use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; class UploaderController implements UploadControllerInterface { @@ -41,6 +42,7 @@ class UploaderController implements UploadControllerInterface public function upload() { + $response = new UploaderResponse(); $totalParts = $this->request->get('qqtotalparts', 1); $files = $this->request->files; $chunked = $totalParts > 1; @@ -49,16 +51,28 @@ class UploaderController implements UploadControllerInterface { try { - $name = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file); + $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file); + + $postUploadEvent = new PostUploadEvent($uploaded, $response, $this->request, $this->type, $this->config); + $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); + + if(!$this->config['use_orphanage']) + { + // dispatch post upload event + $postPersistEvent = new PostPersistEvent($uploaded, $response, $this->request, $this->type, $this->config); + $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); + } } catch(UploadException $e) { + $response->setSuccess(false); + // an error happended, return this error message. - return new JsonResponse(array('error' => $e->getMessage())); + return new JsonResponse($response->assemble()); } } - return new JsonResponse(array('success' => true, 'name' => $name)); + return new JsonResponse($response->assemble()); } protected function handleUpload(UploadedFile $file) @@ -68,25 +82,13 @@ class UploaderController implements UploadControllerInterface $name = $this->namer->name($file, $this->config['directory_prefix']); $uploaded = $this->storage->upload($file, $name); - $postUploadEvent = new PostUploadEvent($file, $this->request, $this->type, array( - 'use_orphanage' => $this->config['use_orphanage'], - 'file_name' => $name - )); - $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); - - if(!$this->config['use_orphanage']) - { - // dispatch post upload event - $postPersistEvent = new PostPersistEvent($uploaded, $this->request, $this->type); - $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); - } - - return $name; + return $uploaded; } protected function handleChunkedUpload(UploadedFile $file) { - $request = $this->request; + $request = $this->request; + $uploaded = null; // getting information about chunks $index = $request->get('qqpartindex'); @@ -113,12 +115,12 @@ class UploaderController implements UploadControllerInterface // validate this entity and upload on success $this->validate($uploadedFile); - $ret = $this->handleUpload(); + $uploaded = $this->handleUpload(); $this->chunkManager->cleanup($path); } - return $name; + return $uploaded; } protected function validate(UploadedFile $file) diff --git a/Event/PostPersistEvent.php b/Event/PostPersistEvent.php index dac4fc9..60fb8f7 100644 --- a/Event/PostPersistEvent.php +++ b/Event/PostPersistEvent.php @@ -7,17 +7,23 @@ use Symfony\Component\HttpFoundation\Request; use Gaufrette\File; +use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; + class PostPersistEvent extends Event { protected $file; protected $request; protected $type; + protected $response; + protected $config; - public function __construct(File $file, Request $request, $type) + public function __construct(File $file, UploaderResponse $response, Request $request, $type, array $config) { $this->file = $file; $this->request = $request; + $this->response = $response; $this->type = $type; + $this->config = $config; } public function getFile() @@ -34,4 +40,14 @@ class PostPersistEvent extends Event { return $this->type; } + + public function getResponse() + { + return $this->response; + } + + public function getConfig() + { + return $this->config; + } } \ No newline at end of file diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php index eb88843..216e58d 100644 --- a/Event/PostUploadEvent.php +++ b/Event/PostUploadEvent.php @@ -5,21 +5,25 @@ namespace Oneup\UploaderBundle\Event; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\File\File; +use Gaufrette\File; + +use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; class PostUploadEvent extends Event { protected $file; protected $request; protected $type; - protected $options; + protected $response; + protected $config; - public function __construct(File $file, Request $request, $type, array $options = array()) + public function __construct(File $file, UploaderResponse $response, Request $request, $type, array $config) { $this->file = $file; $this->request = $request; + $this->response = $response; $this->type = $type; - $this->options = $options; + $this->config = $config; } public function getFile() @@ -37,8 +41,13 @@ class PostUploadEvent extends Event return $this->type; } - public function getOptions() + public function getResponse() + { + return $this->response; + } + + public function getConfig() { - return $this->options; + return $this->config; } } \ No newline at end of file diff --git a/Uploader/Response/UploaderResponse.php b/Uploader/Response/UploaderResponse.php new file mode 100644 index 0000000..4a0511e --- /dev/null +++ b/Uploader/Response/UploaderResponse.php @@ -0,0 +1,73 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Response; + +class UploaderResponse implements \ArrayAccess +{ + protected $success; + protected $error; + protected $data; + + public function __construct() + { + $this->success = true; + $this->error = null; + $this->data = array(); + } + + public function assemble() + { + // explicitly overwrite success and error key + // as these keys are used internaly by the + // frontend uploader + $data = $this->data; + $data['success'] = $this->success; + + if(!$this->success) + $data['error'] = $this->error; + + return $data; + } + + public function offsetSet($offset, $value) + { + is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value; + } + public function offsetExists($offset) + { + return isset($this->data[$offset]); + } + public function offsetUnset($offset) + { + unset($this->data[$offset]); + } + + public function offsetGet($offset) + { + return isset($this->data[$offset]) ? $this->container[$offset] : null; + } + + public function setSuccess($success) + { + $this->success = (bool) $success; + + return $this; + } + + public function getSuccess() + { + return $this->success; + } + + public function setError($msg) + { + $this->error = $msg; + + return $this; + } + + public function getError() + { + return $this->error; + } +} \ No newline at end of file diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php index f7f7aad..27f83ec 100644 --- a/Uploader/Storage/OrphanageStorage.php +++ b/Uploader/Storage/OrphanageStorage.php @@ -33,7 +33,7 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter if(!$this->session->isStarted()) throw new \RuntimeException('You need a running session in order to run the Orphanage.'); - parent::upload($file, $name); + return parent::upload($file, $name); } public function uploadFiles($keep = false)
0
60e17684b0bed682fe7a5ab6dc497f4521522aa8
1up-lab/OneupUploaderBundle
Update response.md This should avoid any confusion whatsoever. /cc #26
commit 60e17684b0bed682fe7a5ab6dc497f4521522aa8 Author: Jim Schmid <[email protected]> Date: Sun Jul 14 12:31:05 2013 +0200 Update response.md This should avoid any confusion whatsoever. /cc #26 diff --git a/Resources/doc/response.md b/Resources/doc/response.md index d55192c..60807e6 100644 --- a/Resources/doc/response.md +++ b/Resources/doc/response.md @@ -20,8 +20,8 @@ class UploadListener The `UploaderResponse` class implements the `ArrayAccess` interface, so you can just add data using it like an array: ```php -$response['id'] = $id; -$response['url'] = $url; +$response['key'] = 'value'; +$response['foo'] = 'bar'; ``` If you like to indicate an error, be sure to set the `success` property to `false` and provide an error message:
0
00e0cef40ff67dc60bbd1130c83d2e5e138567e3
1up-lab/OneupUploaderBundle
Included max_size parameter for mapping-configuration.
commit 00e0cef40ff67dc60bbd1130c83d2e5e138567e3 Author: Jim Schmid <[email protected]> Date: Thu Mar 14 15:45:57 2013 +0100 Included max_size parameter for mapping-configuration. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index 6feeed0..722172d 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -34,6 +34,10 @@ class UploaderController implements UploadControllerInterface foreach($files as $file) { + // some error handling + if($file->getClientSize() > $this->config['max_size']) + return new JsonResponse(array('error' => 'File is too large')); + $ret = $totalParts > 1 ? $this->handleChunkedUpload($file) : $this->handleUpload($file); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 829ae62..04d1ca6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -35,7 +35,8 @@ class Configuration implements ConfigurationInterface ->prototype('array') ->children() ->scalarNode('storage')->isRequired()->end() - ->scalarNode('directory_prefix')->end() + ->scalarNode('max_size')->defaultNull()->end() + ->scalarNode('directory_prefix')->defaultNull()->end() ->booleanNode('use_orphanage')->defaultFalse()->end() ->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end() ->end() diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 4e363cd..e844c04 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -39,11 +39,13 @@ class OneupUploaderExtension extends Extension // handle mappings foreach($config['mappings'] as $key => $mapping) { - if(!array_key_exists('directory_prefix', $mapping)) + if(is_null($mapping['directory_prefix'])) { $mapping['directory_prefix'] = $key; } + $mapping['max_size'] = min(min($mapping['max_size'], ini_get('upload_max_filesize')), ini_get('post_max_size')); + $mapping['storage'] = $this->registerStorageService($container, $mapping); $this->registerServicesPerMap($container, $key, $mapping); }
0
73e39c5eee56d90370af664eb4d118d1ffef0e01
1up-lab/OneupUploaderBundle
Made request passing in ValidationEvent mandatory.
commit 73e39c5eee56d90370af664eb4d118d1ffef0e01 Author: Jim Schmid <[email protected]> Date: Tue Oct 8 21:23:55 2013 +0200 Made request passing in ValidationEvent mandatory. diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 30b0519..04397d2 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -164,7 +164,7 @@ abstract class AbstractController protected function validate(UploadedFile $file) { $dispatcher = $this->container->get('event_dispatcher'); - $event = new ValidationEvent($file, $this->config, $this->type, $this->container->get('request')); + $event = new ValidationEvent($file, $this->container->get('request'), $this->config, $this->type); $dispatcher->dispatch(UploadEvents::VALIDATION, $event); } diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php index 0fa90b0..8110b78 100644 --- a/Event/ValidationEvent.php +++ b/Event/ValidationEvent.php @@ -13,7 +13,7 @@ class ValidationEvent extends Event protected $type; protected $request; - public function __construct(UploadedFile $file, array $config, $type, Request $request = null) + public function __construct(UploadedFile $file, Request $request, array $config, $type) { $this->file = $file; $this->config = $config;
0
eb609baf31012cf67fb776953bdee2bd484e58eb
1up-lab/OneupUploaderBundle
Merge branch 'nathanmarcos-master'
commit eb609baf31012cf67fb776953bdee2bd484e58eb (from 645d01718a7af9815baa95d1c2209bf08f43a4bd) Merge: 645d017 0cad080 Author: David Greminger <[email protected]> Date: Mon Jun 20 09:58:42 2016 +0200 Merge branch 'nathanmarcos-master' diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 276ddf3..75d64b4 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -90,6 +90,7 @@ class Configuration implements ConfigurationInterface ->booleanNode('enable_progress')->defaultFalse()->end() ->booleanNode('enable_cancelation')->defaultFalse()->end() ->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end() + ->booleanNode('root_folder')->defaultFalse()->end() ->end() ->end() ->end() diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 4a471c5..5ffbe09 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -200,8 +200,11 @@ class OneupUploaderExtension extends Extension switch ($config['type']) { case 'filesystem': + // root_folder is true, remove the mapping name folder from path + $folder = $this->config['mappings'][$key]['root_folder'] ? '' : $key; + $config['directory'] = is_null($config['directory']) ? - sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) : + sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $folder) : $this->normalizePath($config['directory']) ; diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index 6b0d248..a7cee8a 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -38,6 +38,7 @@ oneup_uploader: allowed_mimetypes: [] disallowed_mimetypes: [] error_handler: oneup_uploader.error_handler.noop + root_folder: false # Set max_size to -1 for gracefully downgrade this number to the systems max upload size. max_size: 9223372036854775807 diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md index 256d2c6..257451d 100644 --- a/Resources/doc/custom_namer.md +++ b/Resources/doc/custom_namer.md @@ -50,3 +50,57 @@ oneup_uploader: ``` Every file uploaded through the `Controller` of this mapping will be named with your custom namer. + +## Change the directory structure + +With the `NameInterface` you can change the directory structure to provide a better files organization or to use your own existing structure. For example, you need to separate the uploaded files by users with a `user_id` folder. + +You need to inject the `security.token_storage` service to your namer. + +```xml +<services> + <service id="acme_demo.custom_namer" class="Acme\DemoBundle\CatNamer"> + <argument type="service" id="security.token_storage"/> + </service> +</services> +``` + +Now you can use the service to get the logged user id and return the custom directory like below: + +```php +<?php + +namespace Acme\DemoBundle; + +use Oneup\UploaderBundle\Uploader\File\FileInterface; +use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; + +class CatNamer implements NamerInterface +{ + private $tokenStorage; + + public function __construct(TokenStorage $tokenStorage){ + $this->tokenStorage = $tokenStorage; + } + + /** + * Creates a user directory name for the file being uploaded. + * + * @param FileInterface $file + * @return string The directory name. + */ + public function name(FileInterface $file) + { + $userId = $tokenStorage->getToken()->getUser()->getId(); + + return sprintf('%s/%s.%s', + $userId, + uniqid(), + $file->getExtension() + ); + } +} +``` + +Every file uploaded through the `Controller` of this mapping will be named with your new directory structure. \ No newline at end of file diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 5fd3425..0c18f92 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -78,9 +78,19 @@ oneup_uploader: type: uploader ``` -The default directory that is used to upload files to is `web/uploads/{mapping_name}`. +The default directory that is used to upload files to is `web/uploads/{mapping_name}`. In case you want to avoid a separated mapping folder, you can set `root_folder: true` and the default directory will be `web/uploads`. + +```yaml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + root_folder: true +``` > It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you. +> You can improve the directory structure checking the "[Change the directory structure](custom_namer.md#change-the-directory-structure)". ### Step 4: Prepare your frontend
0
42b6ff7e97cf6ccff2402c1000a50f7a1bdf8fc7
1up-lab/OneupUploaderBundle
Print a valuable exception message if filesystem key is empty.
commit 42b6ff7e97cf6ccff2402c1000a50f7a1bdf8fc7 Author: Jim Schmid <[email protected]> Date: Fri Apr 5 20:01:48 2013 +0200 Print a valuable exception message if filesystem key is empty. diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 32d23a5..c828879 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -5,6 +5,7 @@ namespace Oneup\UploaderBundle\DependencyInjection; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; @@ -71,6 +72,9 @@ class OneupUploaderExtension extends Extension if(!class_exists('Gaufrette\\Filesystem')) throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a storage service.'); + if(strlen($mapping['storage']['filesystem']) <= 0) + throw new ServiceNotFoundException('Empty service name'); + $container ->register($storageName, $container->getParameter(sprintf('oneup_uploader.storage.%s.class', $mapping['storage']['type']))) ->addArgument(new Reference($mapping['storage']['filesystem']))
0
210707fefc9f9fe9d14e5aefe361ad7e6c346ef7
1up-lab/OneupUploaderBundle
Merge branch 'lsv-xml-to-yml' into release-1.4.0
commit 210707fefc9f9fe9d14e5aefe361ad7e6c346ef7 (from 59621666d24849e0358617a31df2bd02c0dc5e47) Merge: 5962166 91b5ecc Author: David Greminger <[email protected]> Date: Mon Jan 4 10:08:50 2016 +0100 Merge branch 'lsv-xml-to-yml' into release-1.4.0 diff --git a/Resources/doc/custom_error_handler.md b/Resources/doc/custom_error_handler.md index 4110836..69bedfa 100644 --- a/Resources/doc/custom_error_handler.md +++ b/Resources/doc/custom_error_handler.md @@ -33,6 +33,12 @@ Define a service for your class. </services> ``` +```yml +services: + acme_demo.custom_error_handler: + class: Acme\DemoBundle\ErrorHandler\CustomErrorHandler +``` + And configure the mapping to use your shiny new service. ```yml diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md index 88c6d71..b91091e 100644 --- a/Resources/doc/custom_logic.md +++ b/Resources/doc/custom_logic.md @@ -40,6 +40,15 @@ And register it in your `services.xml`. </services> ``` +```yml +services: + acme_hello.upload_listener: + class: Acme\HelloBundle\EventListener\UploadListener + argument: ["@doctrine"] + tags: + - { name: kernel.event_listener, event: oneup_uploader.post_persist, method: onUpload } +``` + You can now implement you custom logic in the `onUpload` method of your EventListener. ## Use custom input data diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md index 9b59e58..c83002d 100644 --- a/Resources/doc/custom_namer.md +++ b/Resources/doc/custom_namer.md @@ -34,6 +34,12 @@ Next, register your created namer as a service in your `services.xml` </services> ``` +```yml +services: + acme_demo.custom_namer: + class: Acme\DemoBundle\CatNamer +``` + Now you can use your custom service by adding it to your configuration: ```yml diff --git a/Resources/doc/custom_validator.md b/Resources/doc/custom_validator.md index 1f0ef03..2d5b5f0 100644 --- a/Resources/doc/custom_validator.md +++ b/Resources/doc/custom_validator.md @@ -45,3 +45,11 @@ After that register your new `EventListener` in the `services.xml` of your appli </services> </container> ``` + +```yml +services: + acme_demo.always_false_listener: + class: Acme\DemoBundle\EventListener\AlwaysFalseValidationListener + tags: + - { name: kernel.event_listener, event: oneup_uploader.validation, method: onValidate } +``` commit 210707fefc9f9fe9d14e5aefe361ad7e6c346ef7 (from 91b5eccf9d9d1461be052092434dedfdd40d28f5) Merge: 5962166 91b5ecc Author: David Greminger <[email protected]> Date: Mon Jan 4 10:08:50 2016 +0100 Merge branch 'lsv-xml-to-yml' into release-1.4.0 diff --git a/.travis.yml b/.travis.yml index 26b3eb4..f81a416 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ php: - hhvm env: - - SYMFONY_VERSION=2.3.* + - SYMFONY_VERSION=2.4.* - SYMFONY_VERSION=2.7.* - SYMFONY_VERSION=2.8.* @@ -20,11 +20,10 @@ cache: matrix: allow_failures: - php: hhvm + - php: 7.0 - env: SYMFONY_VERSION=dev-master include: - - php: 5.6 - env: SYMFONY_VERSION=2.3.* - php: 5.6 env: SYMFONY_VERSION=2.4.* - php: 5.6 diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index aec580d..7f35224 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -115,7 +115,6 @@ class OneupUploaderExtension extends Extension ->addArgument($key) ->addTag('oneup_uploader.routable', array('type' => $key)) - ->setScope('request') ; return $controllerName; diff --git a/composer.json b/composer.json index 3d9a755..b2f32a3 100644 --- a/composer.json +++ b/composer.json @@ -15,19 +15,18 @@ ], "require": { - "symfony/framework-bundle": "^2.3.0", - "symfony/http-kernel": "^2.3.0", - "symfony/finder": ">=2.2.0" + "symfony/framework-bundle": "^2.4.0|~3.0", + "symfony/finder": "^2.4.0|~3.0" }, "require-dev": { "amazonwebservices/aws-sdk-for-php": "1.5.*", "knplabs/gaufrette": "0.2.*@dev", - "symfony/class-loader": "2.*", - "symfony/security-bundle": "2.*", - "sensio/framework-extra-bundle": "2.*", - "symfony/browser-kit": "2.*", - "phpunit/phpunit": "~4.1" + "symfony/class-loader": "2.*|~3.0", + "symfony/security-bundle": "2.*|~3.0", + "sensio/framework-extra-bundle": "2.*|~3.0", + "symfony/browser-kit": "2.*|~3.0", + "phpunit/phpunit": "~4.4" }, "suggest": {
0
c5a1ce9a0e7b2f84982ccff39ba88832e0602cae
1up-lab/OneupUploaderBundle
Merge branch 'bluntelk-master'
commit c5a1ce9a0e7b2f84982ccff39ba88832e0602cae (from 14eda43b90ac9d08485daf98017c67f1827920fd) Merge: 14eda43 3ecd0b8 Author: David Greminger <[email protected]> Date: Fri Mar 17 12:17:45 2017 +0100 Merge branch 'bluntelk-master' diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml index bf580bf..1f51fb2 100644 --- a/Resources/config/errorhandler.xml +++ b/Resources/config/errorhandler.xml @@ -12,7 +12,9 @@ <services> <service id="oneup_uploader.error_handler.noop" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.fineuploader" class="%oneup_uploader.error_handler.noop.class%" public="false" /> - <service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false" /> + <service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false"> + <argument type="service" id="translator"/> + </service> <service id="oneup_uploader.error_handler.uploadify" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.yui3" class="%oneup_uploader.error_handler.noop.class%" public="false" /> <service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" /> diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php index 7ba1307..871e687 100644 --- a/Tests/Controller/BlueimpValidationTest.php +++ b/Tests/Controller/BlueimpValidationTest.php @@ -2,6 +2,7 @@ namespace Oneup\UploaderBundle\Tests\Controller; +use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Component\HttpFoundation\File\UploadedFile; use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest; use Oneup\UploaderBundle\UploadEvents; @@ -11,6 +12,7 @@ class BlueimpValidationTest extends AbstractValidationTest public function testAgainstMaxSize() { // assemble a request + /** @var Client $client */ $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); @@ -20,6 +22,7 @@ class BlueimpValidationTest extends AbstractValidationTest //$this->assertTrue($response->isNotSuccessful()); $this->assertEquals($response->headers->get('Content-Type'), 'application/json'); $this->assertCount(0, $this->getUploadedFiles()); + $this->assertFalse(strpos($response->getContent(), 'error.maxsize'), "Failed to translate error id into lang"); } public function testEvents() diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php index c8839b7..be5e088 100644 --- a/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -5,12 +5,23 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler; use Exception; use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface; use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; +use Symfony\Component\Translation\TranslatorInterface; class BlueimpErrorHandler implements ErrorHandlerInterface { + /** + * @var TranslatorInterface + */ + private $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + public function addException(AbstractResponse $response, Exception $exception) { - $message = $exception->getMessage(); + $message = $this->translator->trans($exception->getMessage(), array(), 'OneupUploaderBundle'); $response->addToOffset(array('error' => $message), array('files')); } }
0
01718556b0a231a26930fd5e32550992b3d1e350
1up-lab/OneupUploaderBundle
Removed unused dependencies in tests.
commit 01718556b0a231a26930fd5e32550992b3d1e350 Author: Jim Schmid <[email protected]> Date: Tue Aug 13 16:23:31 2013 +0200 Removed unused dependencies in tests. diff --git a/Tests/App/AppKernel.php b/Tests/App/AppKernel.php index 7a15fe8..f1aa6f0 100644 --- a/Tests/App/AppKernel.php +++ b/Tests/App/AppKernel.php @@ -10,9 +10,7 @@ class AppKernel extends Kernel $bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), - new Symfony\Bundle\MonologBundle\MonologBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), - new JMS\SerializerBundle\JMSSerializerBundle($this), // bundle to test new Oneup\UploaderBundle\OneupUploaderBundle(), diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index 5c31e2c..43d37c3 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -10,17 +10,6 @@ framework: session: ~ test: ~ -monolog: - handlers: - main: - type: fingers_crossed - action_level: error - handler: nested - nested: - type: stream - path: %kernel.logs_dir%/%kernel.environment%.log - level: debug - oneup_uploader: mappings: diff --git a/composer.json b/composer.json index df76f99..f2b846a 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,8 @@ "require-dev": { "amazonwebservices/aws-sdk-for-php": "1.5.*", "knplabs/gaufrette": "0.2.*@dev", - "symfony/class-loader": "2.*", "symfony/security-bundle": "2.*", - "symfony/monolog-bundle": "2.*", "sensio/framework-extra-bundle": "2.*", - "jms/serializer-bundle": "dev-master", - "symfony/yaml": "2.*", - "symfony/form": "2.*", - "symfony/twig-bundle": "2.*", "symfony/browser-kit": "2.*", "phpunit/phpunit": "3.7.*" },
0
908cbc408517203a7124c6f9eb45a104b8da9afe
1up-lab/OneupUploaderBundle
Improved compatibility with Symfony 4 (#335)
commit 908cbc408517203a7124c6f9eb45a104b8da9afe Author: okorneliuk <[email protected]> Date: Tue May 22 19:51:22 2018 +0300 Improved compatibility with Symfony 4 (#335) diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index d63804f..6371cd8 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -206,8 +206,8 @@ class OneupUploaderExtension extends Extension // root_folder is true, remove the mapping name folder from path $folder = $this->config['mappings'][$key]['root_folder'] ? '' : $key; - $config['directory'] = null === $config['directory'] ? - sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $folder) : + $config['directory'] = null === $config['directory'] ? + \sprintf('%s/uploads/%s', $this->getTargetDir(), $folder) : $this->normalizePath($config['directory']) ; @@ -327,4 +327,18 @@ class OneupUploaderExtension extends Extension return rtrim($input, '/').'/'; } + + protected function getTargetDir() + { + $projectDir = $this->container->hasParameter('kernel.project_dir') ? + $this->container->getParameter('kernel.project_dir') : + $this->container->getParameter('kernel.root_dir').'/..'; + $publicDir = \sprintf('%s/public', $projectDir); + + if (!is_dir($publicDir)) { + $publicDir = \sprintf('%s/web', $projectDir); + } + + return $publicDir; + } } diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index bdde803..d68d658 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -59,16 +59,12 @@ abstract class AbstractControllerTest extends WebTestCase public function testCallByGet() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException::class); - - $this->implTestCallBy('GET'); + $this->implTestCallBy('GET', 405, 'text/html'); } public function testCallByDelete() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException::class); - - $this->implTestCallBy('DELETE'); + $this->implTestCallBy('DELETE', 405, 'text/html'); } public function testCallByPatch() @@ -101,7 +97,7 @@ abstract class AbstractControllerTest extends WebTestCase abstract protected function getConfigKey(); - protected function implTestCallBy($method) + protected function implTestCallBy($method, $expectedStatusCode = 200, $expectedContentType='application/json') { $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); @@ -109,8 +105,8 @@ abstract class AbstractControllerTest extends WebTestCase $client->request($method, $endpoint, [], [], $this->requestHeaders); $response = $client->getResponse(); - $this->assertTrue($response->isSuccessful()); - $this->assertSame($response->headers->get('Content-Type'), 'application/json'); + $this->assertEquals($expectedStatusCode, $response->getStatusCode()); + $this->assertContains($expectedContentType, $response->headers->get('Content-Type')); } protected function createTempFile($size = 128)
0
be7cdc76ebf067f9fcc733050be4eeab9b0b6195
1up-lab/OneupUploaderBundle
Moved knp-gaufrette-bundle to the 'suggest' section of the composer.json
commit be7cdc76ebf067f9fcc733050be4eeab9b0b6195 Author: Jim Schmid <[email protected]> Date: Fri Apr 5 19:38:55 2013 +0200 Moved knp-gaufrette-bundle to the 'suggest' section of the composer.json diff --git a/composer.json b/composer.json index 9b70844..ac64ad5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,10 @@ "require": { "symfony/finder": ">=2.0.16,<2.3-dev", "symfony/filesystem": ">=2.0.16,<2.3-dev", - "symfony/event-dispatcher": ">=2.0.16,<2.3-dev", + "symfony/event-dispatcher": ">=2.0.16,<2.3-dev" + }, + + "suggest": { "knplabs/knp-gaufrette-bundle": "0.1.*" },
0
b3b58d5d28979a1a2942e4253db068169edc7269
1up-lab/OneupUploaderBundle
Replaced array-input with Traversable-Interface, so you can pass a Finder instance.
commit b3b58d5d28979a1a2942e4253db068169edc7269 Author: Jim Schmid <[email protected]> Date: Fri Apr 5 18:14:02 2013 +0200 Replaced array-input with Traversable-Interface, so you can pass a Finder instance. diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php index 6d4b489..90c48ef 100644 --- a/Uploader/Chunk/ChunkManager.php +++ b/Uploader/Chunk/ChunkManager.php @@ -58,7 +58,7 @@ class ChunkManager implements ChunkManagerInterface $chunk->move($path, $name); } - public function assembleChunks(array $chunks) + public function assembleChunks(\Traversable $chunks) { // I don't really get it why getIterator()->current() always // gives me a null-value, due to that I've to implement this diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php index 4d0068d..7900c61 100644 --- a/Uploader/Chunk/ChunkManagerInterface.php +++ b/Uploader/Chunk/ChunkManagerInterface.php @@ -9,7 +9,7 @@ interface ChunkManagerInterface public function warmup(); public function clear(); public function addChunk($uuid, $index, UploadedFile $chunk, $original); - public function assembleChunks(array $chunks); + public function assembleChunks(\Traversable $chunks); public function cleanup($path); public function getChunks($uuid); } \ No newline at end of file
0
a4956bf77181e763108664c23f217e988e9db8a2
1up-lab/OneupUploaderBundle
Set PHP 5.4 as a minimum requirement, updated upgrade notes
commit a4956bf77181e763108664c23f217e988e9db8a2 Author: David Greminger <[email protected]> Date: Thu Jan 28 16:02:32 2016 +0100 Set PHP 5.4 as a minimum requirement, updated upgrade notes diff --git a/README.md b/README.md index daa5eac..12ae19a 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- +* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @lsv! PR is [here](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). * Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57). * If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320). * Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md). diff --git a/composer.json b/composer.json index 69253bb..b0ef8ce 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ ], "require": { + "php":">=5.4", "symfony/framework-bundle": "^2.4.0|~3.0", "symfony/finder": "^2.4.0|~3.0" },
0
7a778af6c97f793d77453179275b6a98c9907188
1up-lab/OneupUploaderBundle
Add native return type declaration to Configuration::getConfigTreeBuilder (#416)
commit 7a778af6c97f793d77453179275b6a98c9907188 Author: Artem Lopata <[email protected]> Date: Wed Jul 20 11:12:09 2022 +0200 Add native return type declaration to Configuration::getConfigTreeBuilder (#416) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 4426fea..ae0ac4a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -9,7 +9,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('oneup_uploader'); $rootNode = $treeBuilder->getRootNode();
0
aedb105fd7b3c7ee753cde8def6357b96c78fe9b
1up-lab/OneupUploaderBundle
Removed remove() function as we don't need it anyways.
commit aedb105fd7b3c7ee753cde8def6357b96c78fe9b Author: Jim Schmid <[email protected]> Date: Sat Apr 6 19:28:45 2013 +0200 Removed remove() function as we don't need it anyways. diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php index 1058a0d..f756476 100644 --- a/Uploader/Storage/FilesystemStorage.php +++ b/Uploader/Storage/FilesystemStorage.php @@ -33,17 +33,4 @@ class FilesystemStorage implements StorageInterface return $file; } - - public function remove($path) - { - $filesystem = new Filesystem(); - - if($filesystem->exists($path)) - { - $filesystem->remove($path); - return true; - } - - return false; - } } \ No newline at end of file diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index 76633fb..7f3978e 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -46,18 +46,4 @@ class GaufretteStorage implements StorageInterface return $this->filesystem->get($path); } - - public function remove($path) - { - try - { - $this->filesystem->delete($path); - } - catch(\RuntimeException $e) - { - return false; - } - - return true; - } } \ No newline at end of file diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php index 96c807c..3684604 100644 --- a/Uploader/Storage/StorageInterface.php +++ b/Uploader/Storage/StorageInterface.php @@ -7,5 +7,4 @@ use Symfony\Component\HttpFoundation\File\File; interface StorageInterface { public function upload(File $file, $name = null, $path = null); - public function remove($path); } \ No newline at end of file
0
5be2e5b52db91466ee14cf700d048255b8f8df4f
1up-lab/OneupUploaderBundle
Test event dispatching of post update event.
commit 5be2e5b52db91466ee14cf700d048255b8f8df4f Author: Jim Schmid <[email protected]> Date: Thu Jun 20 20:19:29 2013 +0200 Test event dispatching of post update event. diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md index e3cda00..a42926c 100644 --- a/Resources/doc/custom_logic.md +++ b/Resources/doc/custom_logic.md @@ -84,7 +84,6 @@ The Event object provides the following methods. ## Using chunked uploads If you are using chunked uploads and hook into the `oneup_uploader.post_chunk_upload` event, you will get `PostChunkUploadEvent` in your listeners. This Event type differs from the previously introduced ones. You'll have the following methods. - * `getChunk`: Get the chunk file. Is an instance of `Symfony\Component\HttpFoundation\File\File`. * `getRequest`: Get the current request including custom variables. * `getResponse`: Get the response object to add custom return data. diff --git a/Tests/Controller/AbstractUploadTest.php b/Tests/Controller/AbstractUploadTest.php index 8603bd2..754bb8d 100644 --- a/Tests/Controller/AbstractUploadTest.php +++ b/Tests/Controller/AbstractUploadTest.php @@ -3,6 +3,8 @@ namespace Oneup\UploaderBundle\Tests\Controller; use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest; +use Oneup\UploaderBundle\UploadEvents; +use Oneup\UploaderBundle\Event\PostUploadEvent; abstract class AbstractUploadTest extends AbstractControllerTest { @@ -35,4 +37,29 @@ abstract class AbstractUploadTest extends AbstractControllerTest $this->assertEquals(128, $file->getSize()); } } + + public function testEvents() + { + $client = $this->client; + $endpoint = $this->helper->endpoint($this->getConfigKey()); + $dispatcher = $client->getContainer()->get('event_dispatcher'); + + // event data + $me = $this; + $uploadCount = 0; + + $dispatcher->addListener(UploadEvents::POST_UPLOAD, function(PostUploadEvent $event) use (&$uploadCount, &$me) { + ++ $uploadCount; + + $file = $event->getFile(); + + $me->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $file); + $me->assertEquals(128, $file->getSize()); + }); + + $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getRequestFile())); + + $this->assertCount(1, $this->getUploadedFiles()); + $this->assertEquals($uploadCount, count($this->getUploadedFiles())); + } }
0
f6bdd1f3f0639718906808d974279ee286443d03
1up-lab/OneupUploaderBundle
Moved validation to a seperate function to also validate chunked uploads.
commit f6bdd1f3f0639718906808d974279ee286443d03 Author: Jim Schmid <[email protected]> Date: Thu Mar 28 13:23:55 2013 +0100 Moved validation to a seperate function to also validate chunked uploads. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index 7ca7320..f29fff7 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -43,12 +43,13 @@ class UploaderController implements UploadControllerInterface { $totalParts = $this->request->get('qqtotalparts', 1); $files = $this->request->files; + $chunked = $totalParts > 1; foreach($files as $file) { try { - $name = $totalParts > 1 ? $this->handleChunkedUpload($file) : $this->handleUpload($file); + $name = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file); } catch(UploadException $e) { @@ -62,21 +63,7 @@ class UploaderController implements UploadControllerInterface protected function handleUpload(UploadedFile $file) { - // check if the file size submited by the client is over the max size in our config - if($file->getClientSize() > $this->config['max_size']) - throw new UploadException('File is too large.'); - - $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); - - // if this mapping defines at least one type of an allowed extension, - // test if the current is in this array - if(count($this->config['allowed_types']) > 0 && !in_array($extension, $this->config['allowed_types'])) - throw new UploadException('This extension is not allowed.'); - - // check if the current extension is mentioned in the disallowed types - // and if so, throw an exception - if(count($this->config['disallowed_types']) > 0 && in_array($extension, $this->config['disallowed_types'])) - throw new UploadException('This extension is not allowed.'); + $this->validate($file); $name = $this->namer->name($file, $this->config['directory_prefix']); $uploaded = $this->storage->upload($file, $name); @@ -121,11 +108,36 @@ class UploaderController implements UploadControllerInterface $assembled = $this->chunkManager->assembleChunks($chunks); $path = $assembled->getPath(); - $ret = $this->handleUpload(new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true)); + // create a temporary uploaded file to meet the interface restrictions + $uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true); + + // validate this entity and upload on success + $this->validate($uploadedFile); + $ret = $this->handleUpload(); $this->chunkManager->cleanup($path); } return $name; } + + protected function validate(UploadedFile $file) + { + // check if the file size submited by the client is over the max size in our config + if($file->getClientSize() > $this->config['max_size']) + throw new UploadException('File is too large.'); + + $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); + + // if this mapping defines at least one type of an allowed extension, + // test if the current is in this array + if(count($this->config['allowed_types']) > 0 && !in_array($extension, $this->config['allowed_types'])) + throw new UploadException('This extension is not allowed.'); + + // check if the current extension is mentioned in the disallowed types + // and if so, throw an exception + if(count($this->config['disallowed_types']) > 0 && in_array($extension, $this->config['disallowed_types'])) + throw new UploadException('This extension is not allowed.'); + + } } \ No newline at end of file
0