1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-21 06:30:10 -07:00
PrintABrick/src/AppBundle/Controller/DownloadController.php
David Hübner 305d063f2b Merge branch 'feat/3D-view'
Conflicts:
	app/Resources/views/parts/detail.html.twig
	app/Resources/views/sets/detail.html.twig
	src/AppBundle/Controller/PartsController.php
2017-01-21 23:34:59 +01:00

44 lines
1.3 KiB
PHP

<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Model;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/download")
*/
class DownloadController extends Controller
{
/**
* @Route("/model/{id}", name="download_model")
*
* @return Response
*/
public function modelAction(Model $model)
{
$ldraw_filesystem = $this->get('oneup_flysystem.ldraw_filesystem');
if ($ldraw_filesystem->has($model->getFile())) {
$response = new BinaryFileResponse($ldraw_filesystem->getAdapter()->getPathPrefix().$model->getFile());
$response->headers->set('Content-Type', 'application/vnd.ms-pki.stl');
// Create the disposition of the file
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$model->getFile()
);
$response->headers->set('Content-Disposition', $disposition);
return $response;
}
throw new FileNotFoundException($model->getFile());
}
}