/**
* @param mixed $contentId ID of a valid Content
* @param string $fieldIdentifier Field Definition identifier of the Field the file must be downloaded from
* @param string $filename
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \eZ\Bundle\EzPublishIOBundle\BinaryStreamResponse
*/
public function downloadBinaryFileAction($contentId, $fieldIdentifier, $filename, Request $request)
{
if ($request->query->has('version')) {
$content = $this->contentService->loadContent($contentId, null, $request->query->get('version'));
} else {
$content = $this->contentService->loadContent($contentId);
}
$field = $this->translationHelper->getTranslatedField($content, $fieldIdentifier, $request->query->has('inLanguage') ? $request->query->get('inLanguage') : null);
if (!$field instanceof Field) {
throw new InvalidArgumentException("'{$fieldIdentifier}' field not present on content #{$content->contentInfo->id} '{$content->contentInfo->name}'");
}
$response = new BinaryStreamResponse($this->ioService->loadBinaryFile($field->value->id), $this->ioService);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
return $response;
}