|
14 | 14 | use Claroline\CoreBundle\Form\FileType; |
15 | 15 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
16 | 16 | use Symfony\Component\HttpFoundation\JsonResponse; |
17 | | -use Symfony\Component\HttpFoundation\StreamedResponse; |
| 17 | +use Symfony\Component\HttpFoundation\BinaryFileResponse; |
18 | 18 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
19 | 19 | use Symfony\Component\HttpFoundation\Response; |
20 | 20 | use Claroline\CoreBundle\Entity\Resource\File; |
@@ -42,23 +42,19 @@ public function streamMediaAction(ResourceNode $node) |
42 | 42 | { |
43 | 43 | $collection = new ResourceCollection(array($node)); |
44 | 44 | $this->checkAccess('OPEN', $collection); |
45 | | - $file = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node); |
46 | | - $path = $this->container->getParameter('claroline.param.files_directory') . DIRECTORY_SEPARATOR |
47 | | - . $file->getHashName(); |
48 | 45 |
|
49 | | - $response = new StreamedResponse(); |
50 | | - $response->setCallBack( |
51 | | - function () use ($path) { |
52 | | - readfile($path); |
53 | | - } |
54 | | - ); |
55 | | - |
| 46 | + // free the session as soon as possible |
| 47 | + // see https://github.com/claroline/CoreBundle/commit/7cee6de85bbc9448f86eb98af2abb1cb072c7b6b |
56 | 48 | $this->get('session')->save(); |
57 | 49 |
|
| 50 | + $file = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node); |
| 51 | + $path = $this->container->getParameter('claroline.param.files_directory').DIRECTORY_SEPARATOR |
| 52 | + .$file->getHashName(); |
| 53 | + |
| 54 | + $response = new BinaryFileResponse($path); |
58 | 55 | $response->headers->set('Content-Type', $node->getMimeType()); |
59 | | - $response->send(); |
60 | 56 |
|
61 | | - return new Response(); |
| 57 | + return $response; |
62 | 58 | } |
63 | 59 |
|
64 | 60 | /** |
|
0 commit comments