Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Datas from post Multipart (Content-Disposition: form-data) with symfony2

With AngularJS I post form datas and file in one request. I can't handle datas properly in the controller of symfony2.

I only get a full string of datas with $request->getContent() but it is not parsed.

here is more details :

1 - I send data like this example and it works => http://shazwazza.com/post/Uploading-files-and-JSON-data-in-the-same-request-with-Angular-JS

2 - here are datas sent :

-----------------------------23743060120122
Content-Disposition: form-data; name="model"

{"type_inventaire_id":"8","profondeur_id":"2","code_pays_elv":"FR"}
-----------------------------23743060120122
Content-Disposition: form-data; name="file"; filename="importChep.txt"
Content-Type: text/plain

69182002
22096034
22096033
00110011
//69182007
69182003

-----------------------------23743060120122

3 - i can only get datas with $request->getContent() but it is not parsed I would like to get it like that :

$file = $request->files->get('file');
$model = $request->get('model');

I look for a solution for one day but i did not found anything...

Anyone have an idea?

like image 897
C2dric Avatar asked Jul 28 '15 07:07

C2dric


1 Answers

Are you doing a POST or a PUT request? I found out that when using PUT method symfony doesn't give you access to the attributes, however using POST you should be able to access your data:

$file = $request->files->get('file');
$model = $request->request->get('model');
like image 181
Zeux Avatar answered Nov 09 '22 05:11

Zeux