Jump to content

Adding Product Image Via Curl


Recommended Posts

Hi everyone,

 

Over the last days I've been trying to add images to a product using web service. I've followed the official documentation (http://doc.prestashop.com/display/PS16/Chapter+9+-+Image+management) and I just can't do it via CURL.

 

Here's my code:

$url = PS_SHOP_PATH . 'api/images/products/10987';

$image_path = 'C:\\images\\test.jpg';
$key = PS_WS_AUTH_KEY;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

And here's the result:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[66]]></code>
<message><![CDATA[Unable to save this image]]></message>
</error>
</errors>
</prestashop>

I've checked the key permissions twice and everything is ok. I've also read a lot and tryed the solutions of other users but without success.

 

Using the HTML form POST method it works perfeclty...

 

I realy need to do this via CURL. Can anyone help?

 

Thanks in advance.

Link to comment
Share on other sites

I can't believe that after 3 days stucked in this problem and just after few minutes I've decided to ask for help, I found the solution.

 

Anyway... here's how I solve the problem. "Just" adding this line to the code:

curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);

Thanks.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

hello, this's my code.

 

$url = 'http://local-prestashop.com/api/images/products/1';

$image_path = 'D:\\jpg.jpg';
//$image_path = $image['url'];
$key = '8T43CVUNAH7P19UFQGX1PDHUAT6AXL48';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

 

return <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <errors> <error> <code></code> <message></message> </error> </errors> </prestashop>

please help me?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...