0

I want to upload a html file using symfony but always I get an error

Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed 

the code of my class docuement is given as follow

class document
{

    /* ... */

    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="filename", type="string", length=255, nullable=true)
     */
    private $filename;

    /**
     * @var string
     *
     * @ORM\Column(name="realfilename", type="string", length=255, nullable=true)
     */
    private $realfilename;

    /**
     * @Assert\File(
     *   maxSize = "5000k",
     *   mimeTypes = {"text/comma-separated-values", "application/pdf", "text/csv", "application/csv", "application/excel", "application/vnd.ms-excel", "application/vnd.msexcel", "application/octet-stream","text/plain"},
     * )
     */
    private $file

    /* ... */
}

the function that can do the serialization is

$serialize = serialize($docuement);
$encodingDoc = $serviceUtils->encode($serialize, $this->container->getParameter('key_encrypt'));

when I upload a pdf file ou cvs file, everything work great, but when I try to upload html file, I get an error

Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed 

any help please

2
  • 2
    We need to post here your code, otherwise we can't help you. Commented Feb 16, 2016 at 14:18
  • modifyed with my code Commented Feb 16, 2016 at 14:30

1 Answer 1

1

Since you say it works well with *.psd and *.csvbut doesn't work with *.html it might be just because of the @Assert\File annotation which allows mimetypes for psd and csv but doesn't allow html files.

HTML files should be identified by text/html mimetype so try adding text/html to the list of allow mime types in @Assert\File and see if it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

the problem is when calling serialize function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.