Skip to content

Fix File Upload Example #18722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.4
Choose a base branch
from
Open

Fix File Upload Example #18722

wants to merge 1 commit into from

Conversation

nacholibre
Copy link
Contributor

@nacholibre nacholibre commented Aug 8, 2023

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.

@carsonbot carsonbot added this to the 5.4 milestone Aug 8, 2023
@OskarStark OskarStark requested a review from xabbuh August 14, 2023 08:12
@OskarStark
Copy link
Contributor

The explanation looks reasonable to me, WDYT @javiereguiluz ?

@xabbuh xabbuh modified the milestones: 5.4, 6.4 Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants