I've created an endpoint in Paw (and/or Postman) for handling file uploads. It works great!
It's pretty simple. And in my application I can do something like:
echo file_get_contents('php://input');
And it will print out an encoded representation of the image/file (a cute kitten).
The problem is, I cannot seem to reproduce this behaviour using just cURL (Current application uses Guzzle).
When I try something like:
$target_url = 'http://my-document-handling-service.net:8000/documents';
$request = curl_init($target_url);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_POSTREDIR, 3);
curl_setopt(
$request,
CURLOPT_POSTFIELDS,
array(
'file' => '/Users/xxxxxxx-xxxx/Documents/kitten-test-upload-image-1.jpg'
));
echo curl_exec($request);
curl_close($request);
The body (file_get_contents()
) is always empty. I don't really understand cURL I've always just used Guzzle - but now I have to use cURL and I can't get the body.
What am I doing wrong?