Skip to content

Instantly share code, notes, and snippets.

@0GiS0
Created January 31, 2019 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0GiS0/ff6884d23992bb9173da21ea012580a9 to your computer and use it in GitHub Desktop.
Save 0GiS0/ff6884d23992bb9173da21ea012580a9 to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use App\Service\BlobService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class BlobsController extends AbstractController
{
/**
* @Route("/", name="blobs")
*/
public function index(BlobService $storage)
{
return $this->render('blobs/index.html.twig', [
'controller_name' => 'BlobsController',
'blobs' => $storage->allBlobs(),
'containers' => $storage->allContainers(),
]);
}
/**
* @Route("/upload/image", methods={"POST"})
*/
public function create(Request $request, BlobService $storage)
{
$file = $request->files->get('newFile');
if (empty($file)) {
return new Response("No file specified", Response::HTTP_UNPROCESSABLE_ENTITY, ['content-type' => 'text/plain']);
}
$storage->upload($file);
return $this->redirectToRoute('blobs');
}
/**
* @Route("/delete/{blobName}")
*/
public function deleteBlob($blobName, BlobService $storage)
{
$storage->delete($blobName);
return $this->redirectToRoute('blobs');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment