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:
parent
c71bfcf022
commit
37a2e93416
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@
|
||||
/node_modules/
|
||||
/app/Resources/assets/semantic/dist
|
||||
/web/resources/
|
||||
.php_cs.cache
|
||||
|
File diff suppressed because one or more lines are too long
43
src/AppBundle/Controller/DownloadController.php
Normal file
43
src/AppBundle/Controller/DownloadController.php
Normal 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());
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
/**
|
||||
* @Route("rebrickable/part")
|
||||
* @Route("/rebrickable/part")
|
||||
*/
|
||||
class PartController extends Controller
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user