public function postAction(Request $request, $parent = null)
    {
        $title = trim($request->request->get('title'));

        if (!$this->isGranted('CREATE', $parent)) {
            throw new AccessDeniedHttpException(sprintf('You are not authorized to create %s MediaFolder.', $title));
        }

        try {
            $uid = $request->request->get('uid', null);
            if (null !== $uid) {
                $mediaFolder = $this->getMediaFolderRepository()->find($uid);
                $mediaFolder->setTitle($title);
            } else {
                $mediaFolder = new MediaFolder();
                $mediaFolder->setUrl($request->request->get('url', StringUtils::urlize($title)));
                $mediaFolder->setTitle($title);
                if (null === $parent) {
                    $parent = $this->getMediaFolderRepository()->getRoot();
                }

                if ($this->mediaFolderAlreadyExists($title, $parent)) {
                    throw new BadRequestHttpException(sprintf(
                        'A MediaFolder named `%s` already exists in `%s`.',
                        $title,
                        $parent->getTitle()
                    ));
                }

                $mediaFolder->setParent($parent);
                $this->getMediaFolderRepository()->insertNodeAsLastChildOf($mediaFolder, $parent);
            }

            $this->getEntityManager()->persist($mediaFolder);
            $this->getEntityManager()->flush();

            $response = $this->createJsonResponse(null, 201, [
                'BB-RESOURCE-UID' => $mediaFolder->getUid(),
                'Location'        => $this->getApplication()->getRouting()->getUrlByRouteName(
                    'bb.rest.media-folder.get',
                    [
                        'version' => $request->attributes->get('version'),
                        'uid'     => $mediaFolder->getUid(),
                    ],
                    '',
                    false
                ),
            ]);
        } catch (\Exception $e) {
            $response = $this->createResponse(sprintf('Internal server error: %s', $e->getMessage()));
        }

        return $response;
    }