Answer the question
In order to leave comments, you need to log in
POST image from Laravel?
First, an API request comes in , with an image attached to it.
Next, in the controller, I have to send this image using the POST method to another API.
In the controller, I receive the file, and with the help of the SDK from the second API, I send it. The documentation says that you need to send the image using the POST method.
I use $image = Input::file('img')
BUT I get not an image, but apparently a path. Here's what's in the image variable : /tmp/phpxtlLt4
A function from the SDK to which I pass the image (in this example, image):
$params = ["img" => '@'.$image]
$params = array_merge($this->auth_params, $params);
$url = $this->api_server_url . "$method";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$result = null;
if (!empty($data))
{
$result = json_decode($data);
}
return $result;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question