FOSRestBundle icon indicating copy to clipboard operation
FOSRestBundle copied to clipboard

Array normalizer and file upload

Open lukepass opened this issue 6 years ago • 0 comments

Hello, I noticed that the body listener isn't normalizing file fields:

    body_listener:
        # transforms underscored keys to camel cased ones
        # http://symfony.com/doc/master/bundles/FOSRestBundle/body_listener.html
        array_normalizer:
            service: fos_rest.normalizer.camel_keys
            forms: true

If I upload a file field called media_file, this won't be converted to mediaFile. I think the problem lies here:

        if (null !== $this->arrayNormalizer && $normalizeRequest) {
            $data = $request->request->all();

            try {
                $data = $this->arrayNormalizer->normalize($data);
            } catch (NormalizationException $e) {
                throw new BadRequestHttpException($e->getMessage());
            }

            $request->request = new ParameterBag($data);
        }

Shouldn't it be $data = array_merge($request->request->all(), $request->files->all());?

Thanks!

lukepass avatar Mar 27 '19 09:03 lukepass