Reputation: 1213
I have an endpoint which is receiving updates from a service for my subscribers to my app (using a 3rd party api). These are getting sent to me as a post. I don't know how to get the content I've tried few things).
this is what's being received each files has unique generated number
UPLOADED FILES updates: update1389874969000.json (application/json)
This code I've tried -
$request = $this->getRequest();
$request->request->get('updates');
// don't get an error but don't get any data or
$request = $this->getRequest();
$request->files->get('updates');
get '/tmp/php0oJ2oP' which doesn't mean anything to me
Any ideas how to parse this json data, thanks
Upvotes: 0
Views: 1812
Reputation: 48865
public function postAction(Request $request)
{
$personData = json_decode($request->getContent(),true);
Ok. So your are not receiving json as content. Instead, a json file is being uploaded.
The /tmp/php0oJ2oP that you got is actually the path to your uploaded file. You can read and convert to a php array with
$data = json_decode(file_get_contents('/tmp/php0oJ2oP'),true);
Of course you will get a different tmp path for each upload so pull the path from the request.
More info on file uploads can be found here: http://symfony.com/doc/current/reference/forms/types/file.html
But all you really need is the tmp path.
Upvotes: 2