Skip to content

Instantly share code, notes, and snippets.

@adadgio
Last active January 14, 2022 13:40
Show Gist options
  • Save adadgio/165ac61d7727152dcf04c9d994dec0f7 to your computer and use it in GitHub Desktop.
Save adadgio/165ac61d7727152dcf04c9d994dec0f7 to your computer and use it in GitHub Desktop.
// if not on symfony, adapt... but logic is here !
<?php
namespace Medical\CoreBundle\Controller;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Adadgio\RocketBundle\Component\Response\JsonResponse;
use Medical\CoreBundle\Entity\Document;
use Medical\CoreBundle\Utils\OwnerObject;
use Dilab\Resumable;
use Dilab\Network\SimpleRequest;
use Dilab\Network\SimpleResponse;
class UploadController extends Controller
{
/**
* @Route("/upload/document", name="upload_document", options={"expose"=true})
* @Method({"POST","GET"})
*/
public function indexAction()
{
$em = $this
->getDoctrine()
->getManager();
$request = new SimpleRequest();
$response = new SimpleResponse();
$resumable = new Resumable($request, $response);
$resumable->tempFolder = $this->getParameter('medical_core.resumable_uploads')['tmp_dir'];
$resumable->uploadFolder = $this->getParameter('medical_core.resumable_uploads')['upload_dir'];
$resumable->process();
if ($resumable->isUploadComplete()) {
// persist a document
$document = new Document();
// $filename = $resumable->getFilename();
$filename = $resumable->getOriginalFilename(Resumable::WITHOUT_EXTENSION);
$filepath = $resumable->getFilepath();
$doctype = $resumable->getExtension();
$document
->setLabel($filename)
->setDoctype($doctype)
->setViewable(false)
->setPublished(false)
;
// first persist the document
$em->persist($document);
$em->flush();
// now move the uploaded file in the document assets
$document->saveFile('main', $doctype, null, $filepath);
return JsonResponse::fire(array('success' => true, 'message' => 'upload_success', 'filename' => $filename, 'doctype' => $doctype), 200);
}
return JsonResponse::fire(array('success' => true, 'message' => 'chunk_uploaded'), 200);
}
}
@daniyalnamdar
Copy link

Hello, I am trying the dilab resumable.php with Symfony 5 I think the package doesn't get called and I get this error message can you help me with that :
{"message":"Cannot autowire argument $resumable of "App\Controller\upload::store()": it references class "Dilab\Resumable" but no such service exists.","errors":null,"data":{"file":"/var/www/start-api/vendor/symfony/dependency-injection/Container.php","line":416}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment