Adriel Werlich
Adriel Werlich

Reputation: 2331

On loading vich uploader image on Twig template showing File not uploadable exception

I´m facing a challenge when trying to show a image that was uploaded using vich uploader on twig template. An error message is going like this:

   <img src="{{ vich_uploader_asset(manchete.arquivoDaImagem, 'arquivoDaImagem') }}">

But it´s throwing an error message like this:

An exception has been thrown during the rendering of a template ("The class "Symfony\Component\HttpFoundation\File\File" is not uploadable. If you use annotations to configure VichUploaderBundle, you probably just forgot to add @Vich\Uploadable on top of your entity. If you don't use annotations, check that the configuration files are in the right place. In both cases, clearing the cache can also solve the issue.").

My Manchete entity

/**
 * @ORM\Entity(repositoryClass="App\Repository\MancheteRepository")
 * @Vich\Uploadable
 */
class Manchete { ...

The file attribute is like this:

/**
 * @Vich\UploadableField(mapping="manchete_images", fileNameProperty="caminhoDaImagem")
 * @var File
 */
private $arquivoDaImagem;

Any idea what´s happening here?

Upvotes: 0

Views: 837

Answers (1)

Adriel Werlich
Adriel Werlich

Reputation: 2331

I found I was passing:

<img src="{{ vich_uploader_asset(manchete.arquivoDaImagem, 'arquivoDaImagem') }}">

The correct approach is to pass:

<img src="{{ vich_uploader_asset(manchete, 'arquivoDaImagem') }}">

now it works.

Upvotes: 0

Related Questions