Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Claroline\CoreBundle\Form\FileType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Response;
use Claroline\CoreBundle\Entity\Resource\File;
Expand Down Expand Up @@ -42,23 +42,19 @@ public function streamMediaAction(ResourceNode $node)
{
$collection = new ResourceCollection(array($node));
$this->checkAccess('OPEN', $collection);
$file = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node);
$path = $this->container->getParameter('claroline.param.files_directory') . DIRECTORY_SEPARATOR
. $file->getHashName();

$response = new StreamedResponse();
$response->setCallBack(
function () use ($path) {
readfile($path);
}
);

// free the session as soon as possible
// see https://github.com/claroline/CoreBundle/commit/7cee6de85bbc9448f86eb98af2abb1cb072c7b6b
$this->get('session')->save();

$file = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node);
$path = $this->container->getParameter('claroline.param.files_directory').DIRECTORY_SEPARATOR
.$file->getHashName();

$response = new BinaryFileResponse($path);
$response->headers->set('Content-Type', $node->getMimeType());
$response->send();

return new Response();
return $response;
}

/**
Expand Down