Commit 95ffe933 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

UploadController: ajout de getAction.

Showing with 39 additions and 0 deletions
+39 -0
......@@ -16,8 +16,11 @@ use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\RouterInterface;
/**
......@@ -146,6 +149,41 @@ class UploadController extends Controller
);
}
/**
* @Route("/{id}", name="file_upload_get")
* @Method("GET")
* @param Request $request
* @param UploadedFile $file
*/
public function getAction(Request $request, UploadedFile $file)
{
$this->validateToken($request);
if(!$file->isValid()) {
throw new NotFoundHttpException();
}
$response = StreamedResponse::create(function() use($file) { echo $file->getContent(); })
->setPrivate()
->setLastModified($file->getLastModified())
->setEtag($file->getChecksum());
$response->headers->add(
[
'Content-Type' => $file->getMimeType(),
'Content-Length' => $file->getSize(),
'Content-Disposition' => $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$file->getOriginalFilename()
),
]
);
$response->isNotModified($request);
return $response;
}
/**
* @Route("/{id}", name="file_upload_delete")
* @Method("DELETE")
......@@ -157,6 +195,7 @@ class UploadController extends Controller
$this->validateToken($request);
$this->fileManager->delete($file);
return $this->createResponse();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment