public function updateFileRequest(Request $request)
    {
        $original = $this->requestStack->getMasterRequest();
        $input = $original ? $original->getContent() : false;

        if (!$input) {
            return $request;
        }

        $part = new Part((string) $request);

        if ($part->isMultiPart()) {
            // do we have metadata? for a multipart form
            $metadata = $part->getPartsByName('metadata');
            if (is_array($metadata) && !empty($metadata)) {
                $request->request->set('metadata', $metadata[0]->getBody());
            }

            // the file itself
            $upload = $part->getPartsByName('upload');
            if (is_array($upload) && !empty($upload)) {
                $uploadPart = $upload[0];

                $file = $this->extractFileFromString(
                    $uploadPart->getBody(),
                    $uploadPart->getFileName()
                );

                $request->files->add([$file]);
            }
        } elseif ((strpos($request->headers->get('Content-Type'), 'application/json') !== false)
            && $json = json_decode($part->getBody(), true)
        ) {
            // Type json and can be parsed
            $request->request->set('metadata', json_encode($json));
        } else {
            // Anything else should be saved as file
            $file = $this->extractFileFromString($part->getBody());
            if ($file) {
                $request->files->add([$file]);
            }
        }

        return $request;
    }