I am currently receiving the following error:
\"The form\'s view data is expected to be an instance of class Symfony\\Component\\HttpFoundation\\File
Here is the answer:
{
$builder
->add('file', FileType::class, array('data_class' => null))
->add('coverFile', FileType::class, array('data_class' => null))
->add('coverFile', FileType::class, array('data_class' => null,'required' => false))
->add('songName', TextType::class)
->add('songAuthor', TextType::class);
}
/**
* @ORM\Column(type="string")
*
* @Assert\NotBlank(message="Please, upload the song as a MP3 file.")
* @Assert\File(mimeTypes={ "audio/mpeg", "audio/wav", "audio/x-wav", "application/octet-stream" })
*/
private $file;
You tell doctrine that you want to store a string, but you render an upload button in the form which send you a physic file which you do not want to store in your database at all. Instead you want to move the file from a temporary directory to your upload directory, and you want to remember the name of the file into the database wherefore you need this property which is a string.
Best way is to follow this page