Serialization of UploadedFile is not allowed fix

Serialization of UploadedFile is not allowed fix

If you are doing file uploads in Symfony2 with help from the cookbook tutorial you might have ran into the following error:

Serialization of ‘Symfony\Component\HttpFoundation\File\UploadedFile’ is not allowed.

The solution I came up with involves excluding the public $file field from serialization. That way we bypass the exception.

One catch, though: this will exclude all fields that are not protected.

Add the following function to your entity:

Enjoy!

6 Responses so far.

  1. blinbdn says:

    Im trying to use this gist but __sleep magic function doesnt works in my entity.

    I dont know what happens.

  2. Metod says:

    Do you have all serializable fields marked as “protected”? Private or public fields will be ignored.

  3. luc says:

    OMG, that’s save my life !!

  4. Youcef says:

    Hi, I’m a beginner in laravel (it use Symfony component), and i have the same problem , how can i resolve it ?