Jump to content

Someone was able to modify existing images of a product using the api?


qhe
 Share

Recommended Posts

I have two weeks testing and looking for documentation but I can not do it.

I have prestashop 1.5.4.1 and use this code from Chapter 9 - Image management. It works to add images but not modify:

I want to change the image 33 of the product 9 with a new image

 

<?php
define('PS_SHOP_PATH', 'http://myhost.com/testshop/api/images/products/9/33'); // id_product = 9 id_image = 33 (33.jpg)
define('PS_WS_AUTH_KEY', 'RNOLmy key');
$img=$_SERVER["DOCUMENT_ROOT"].'/testshop/img/tmp/newimagefor33.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, PS_SHOP_PATH);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image . I do it
curl_setopt($ch, CURLOPT_USERPWD,  PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$img));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
?>

 

It does not work (does nothing)

<?php
define('PS_SHOP_PATH', 'http://myhost.com/testshop/api/images/products/9/33'); // id_product = 9 id_image = 33 (33.jpg)
define('PS_WS_AUTH_KEY', 'RNOLmy key');
$img=$_SERVER["DOCUMENT_ROOT"].'/testshop/img/tmp/newimagefor33.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, PS_SHOP_PATH);
//curl_setopt($ch, CURLOPT_POST, true); //<--- I comment this
curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image
curl_setopt($ch, CURLOPT_USERPWD,  PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$img));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
?>

 

It does not work.

 

What am I doing wrong?

Is there another way?

Could delete the image and then add it back. Anyone know how to delete an existing image using the api?

 

 

Thank you very much.

Regards,

 

Quim

Edited by qhe (see edit history)

Share this post


Link to post
Share on other sites

  • 2 months later...

Hi

 

If the image is a jpg try to change the POSTFIELDS bit of the code

 

From:

curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));
 
To:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path.';type=image/jpg'));
 
Vivek

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More