0

I'm trying to create a service to upload a file and I'm calling ContainerInterface but I got the error no such service File Uploader Service:

<?php

namespace App\Service;
//use Symfony\Component\DependencyInjection\ContainerBuilder;

//use Psr\Container\ContainerInterface as ContainerInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\DependencyInjection\ContainerInterface;

class FileUploader{
    private $container;

  /**
   * @var ContainerInterface 
   */

    public function __construct(ContainerInterface $container)
    {
        $this->container=$container;
        
    }
    public function  uploadFile(UploadedFile $file){
        $filename=md5(uniqid()).'.'.$file->guessClientExtension();

      
        $file->move(
            $this->container->getParameter('uploads_dir'),$filename
        );
        return $filename;
    }
}
  • 1
    If you're wanting access to the parameters, use the ParameterBagInterface instead. `use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;` – Bossman Feb 08 '22 at 10:52
  • Please, try to named your class `FileUploaderService` instead of FileUploader and be sure that the name of the file is `FileUploaderService.php` – jean-max Feb 08 '22 at 12:10

0 Answers0