0

I have a really simple controller (with FOSRESTBundle)

/**
 * @Rest\Post("/posts/{id}/attachments", name="api_create_attachment", requirements={"pId"="\d+"})
 * @Rest\View()
 */
public function createAttachments(Request $request)
{
    /** @var UploadedFile $attachment */
    $attachment = $request->files->get('file');

    return $attachment->getFilename();
}

I just want to dump the filename from POST request of /api/posts/{id}/attachments. I use Postman with the Content-Type: multipart/form-data header for allowing the file to be send.

Now, i have two files (pp.jpg: 163kb and para.jpg: 358kb). When i try to send the request with pp.jpg it's working perfectly and it return "phpyl3yNE" (the filename). But now, when i'm trying with para.jpg which is not really different, it return me an error "Call to a member function getFilename() on null". And it's the same with many differents files ! I can't figure out why ... i use the symfony serve command for the server and from phpinfo, post_max_size is set to 8M and upload_max_filesize is set to 2M.

I'm stuck at this point .. I can't figure out why it return me null ...

Thank you, have a nice day !

Anthocnt
  • 13
  • 2
  • check your php.ini – Shkar Sardar Dec 13 '19 at 18:24
  • Check this answer: https://stackoverflow.com/a/16022213/1537154, in short, try not to set the headers yourselves or make sure you add the boundary field. If this doesn't solve anything, can you dump your request variable? – Jeroen Dec 14 '19 at 10:10
  • Thank you @Jeroen, i will try as soon as possible and come back to you :) – Anthocnt Dec 16 '19 at 01:48

0 Answers0