使用AngularJS,我在一个请求中发布表单数据和文件。我不能在symfony2的控制器中正确处理数据。
我只得到一个完整的字符串的数据与$request->getContent()
,但它没有被解析。
这里有更多的细节:
1 -我发送数据像这个例子,它的工作=> http://shazwazza.com/post/Uploading-files-and-JSON-data-in-the-same-request-with-Angular-JS
2 -这里是发送的数据:
-----------------------------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 -我只能获得$request->getContent()
的数据,但它没有被解析我希望它是这样的:
$file = $request->files->get('file');
$model = $request->get('model');
我寻找了一天的解决方案,但我没有找到任何东西…
有人知道吗?
您是在做POST还是PUT请求?我发现,当使用PUT方法symfony不给你访问属性,但使用POST你应该能够访问你的数据:
$file = $request->files->get('file');
$model = $request->request->get('model');