symfony-docs icon indicating copy to clipboard operation
symfony-docs copied to clipboard

Fix File Upload Example

Open nacholibre opened this issue 1 year ago • 1 comments

Currently the example suggests to execute this code when doing edit

$product->setBrochureFilename(
    new File($this->getParameter('brochures_directory').'/'.$product->getBrochureFilename())
);

this is wrong in couple of ways

First the setBrochureFilename method expects string and not a File instance. No error is thrown because the File instance can be casted to string and will return the full path, which is not what's needed. In the database field you need to store the filename only, and not the full path.

Second the form expects File instance and not the entity. This is why the form data needs to be changed and not the entity.

In the 4.4 branch it's the same.

nacholibre avatar Aug 08 '23 09:08 nacholibre

The explanation looks reasonable to me, WDYT @javiereguiluz ?

OskarStark avatar Dec 09 '23 09:12 OskarStark