diff --git a/core/modules/file/src/Controller/FileUploadController.php b/core/modules/file/src/Controller/FileUploadController.php index 0bbc8e0..cd3be96 100644 --- a/core/modules/file/src/Controller/FileUploadController.php +++ b/core/modules/file/src/Controller/FileUploadController.php @@ -6,6 +6,7 @@ use Drupal\Core\File\FileSystem; use Drupal\file\FileInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -19,14 +20,18 @@ class FileUploadController extends ControllerBase { * @var \Drupal\Core\File\FileSystem */ protected $fileSystem; + protected $serializer; /** * Constructs a FileUploadController instance. * * @param \Drupal\Core\File\FileSystem $file_system + * @param Symfony\Component\Serializer\SerializerInterface $serializer + * */ - public function __construct(FileSystem $file_system) { + public function __construct(FileSystem $file_system, SerializerInterface $serializer) { $this->fileSystem = $file_system; + $this->serializer = $serializer; } /** @@ -34,7 +39,8 @@ public function __construct(FileSystem $file_system) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('file_system') + $container->get('file_system'), + $container->get('serializer') ); } @@ -59,7 +65,9 @@ public function upload(Request $request, FileInterface $file) { // Save the file so file size is re-calculated. $file->save(); - return new Response('OK'); + // Prepare response. + $normalized_file = $this->serializer->normalize($file); + return new Response($this->serializer->encode($normalized_file, 'json')); } /**