Skip to content

Commit

Permalink
feature(image-upload): Throw exception if invalid file uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Yousef Chanan committed Apr 19, 2016
1 parent fa87a68 commit e35695d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions EventListener/ImageUploadListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Webburza\Sylius\ArticleBundle\Entity\Article;

class ImageUploadListener
Expand All @@ -25,6 +26,10 @@ public function uploadArticleImage(GenericEvent $event)
}

if ($subject->getImage()->hasFile()) {
if (!$subject->getImage()->getFile()->isValid()) {
throw new HttpException(400, 'File is not valid.');
}

$this->uploader->upload($subject->getImage());
}
else {
Expand Down

0 comments on commit e35695d

Please sign in to comment.