1
0
mirror of https://github.com/flarum/core.git synced 2025-10-26 21:21:28 +01:00

Validate PSR-compatible file upload

Instead of converting the uploaded file object to an UploadedFile
instance from Symfony, because the latter is compatible with
Laravel's validation, let's re-implement the validation for the
three rules we were using.

The benefit: we can now avoid copying the uploaded file to a
temporary location just to do the wrapping.

In the next step, we will remove the temporary file and let the
uploader / Intervention Image handle the PSR stream directly.
This commit is contained in:
Franz Liedke
2020-04-09 22:45:49 +02:00
parent 4c50c8d77a
commit 1cbb2a365e
2 changed files with 70 additions and 17 deletions

View File

@@ -18,7 +18,6 @@ use Flarum\User\Event\AvatarSaving;
use Flarum\User\UserRepository;
use Illuminate\Contracts\Events\Dispatcher;
use Intervention\Image\ImageManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class UploadAvatarHandler
{
@@ -65,6 +64,7 @@ class UploadAvatarHandler
* @param UploadAvatar $command
* @return \Flarum\User\User
* @throws \Flarum\User\Exception\PermissionDeniedException
* @throws \Flarum\Foundation\ValidationException
*/
public function handle(UploadAvatar $command)
{
@@ -82,15 +82,6 @@ class UploadAvatarHandler
$file->moveTo($tmpFile);
try {
$file = new UploadedFile(
$tmpFile,
$file->getClientFilename(),
$file->getClientMediaType(),
$file->getSize(),
$file->getError(),
true
);
$this->validator->assertValid(['avatar' => $file]);
$image = (new ImageManager)->make($tmpFile);