Trying to upload an image to prestashop using the api, The image i want is stored on a 3rd server so I first download to the server my app is running (the one making the webservice calls) and trying to upload to prestashop with no success.
My code
$product_id = "1707"; $image_name = "sample_image.jpg"; $image_url = "http://www.test.com/images/sample_image.jpg"; $image_path = "img_tmp/" . $image_name; // folder on the app's server copy($image_url, $image_path); // copy image to server directory from remote $url = "http://192.168.10.5/presta17"; $urlImage = $url.'/api/images/products/'.$product_id.'/'; $image_mime = 'image/jpg'; $args['image'] = new CurlFile($image_path, $image_mime); $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLINFO_HEADER_OUT, 1); curl_setopt($ch, CURLOPT_URL, $urlImage); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERPWD, getenv('WEBSERVICE_KEY').':'); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (200 == $httpCode) { echo 'Product image was successfully created.'; }else{ echo $httpCode; }
Trying this I get error code 26 from Curl and have no idea why.
Image is copied from remote to local server with success so the app has write access to the directory.
Any help appreciated.