1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-20 06:00:08 -07:00

Add model download action

This commit is contained in:
David Hübner 2017-01-21 23:21:06 +01:00
parent c71bfcf022
commit 37a2e93416
4 changed files with 45 additions and 2 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@
/node_modules/ /node_modules/
/app/Resources/assets/semantic/dist /app/Resources/assets/semantic/dist
/web/resources/ /web/resources/
.php_cs.cache

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,43 @@
<?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="model_download")
*
* @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());
}
}

View File

@ -6,7 +6,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/** /**
* @Route("rebrickable/part") * @Route("/rebrickable/part")
*/ */
class PartController extends Controller class PartController extends Controller
{ {