Jump to content

[webservice] Uploading a file


gregM57

Recommended Posts

Hello everyone,

I'm currently working with my team on a prestashop project for a couple of month and all of us were waiting for the version 1.4. Now that it has been released, we're encountering some bugs, some of them has been solved (mainly by us) but others are still remaining!!

The main subject of this topic is how to upload a file ?? We've found out that in the WebserviceRequest file line 1852, a code has been created to add a node image to the current xml. Unfortunately it doesn't work at all! It only returns the existing list without our new node! See code bellow.

if ($available_image_ids)
                           {
                               $this->_xmlOutput .= ''."\n";
                               foreach ($available_image_ids as $available_image_id)
                                   $this->_xmlOutput .= ''."\n";
                               $this->_xmlOutput .= ''."\n";
                               return true;
                           }



Does anyone succeed to upload a new image ? Are we the only one having this problem ?

By the way where is the documentation ???

Warm regards

Greg.

Link to comment
Share on other sites

Sure,

$curl = curl_init();
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, ‘http://your-site.com/api/images/products/10/1’);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, ‘CURLAUTH_BASIC’);
curl_setopt($curl, CURLOPT_USERPWD, ‘FHKEHFHFHHGFHRG3PLVQT3C1QUNM:’);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($curl);
curl_close($curl); 



Ps : Thanks to Tarmax for the explications

  • Like 1
Link to comment
Share on other sites

It looks like the image file should be named "image", but when I set $data to this I'm getting "bad request". Any ideas why?

$data = array('xml'=>$xml, 'image'=>"@"."/var/www/img/logo.jpg");



(I'm POST:ing it to /api/images/products/14/1)

Link to comment
Share on other sites

  • 3 months later...

Hi,

This topic is quite old but I think I may have the answer to this.

In your case, you should POST to /api/images/products/14 where 14 is the product_id.

You should add also the mime-type of the image and the xml data is not required.

$data = array('image'=>"@"."/var/www/img/logo.jpg;type=image/jpeg");



Damien

Link to comment
Share on other sites

  • 8 months later...

Hi.

 

This topic is old sure, but there are not a lot topics with this subject.

 

Do you know how can i have the picture ID after uploading.

 

In effect with PS 1.4.7 you mut to make a product association afte pictures uploading and some other actions.

PS Webservice API don't make this alone

 

After uploading Prestashop send one more time the picture in response after uploding (1.4.7) and send nothing else (no xml).

This is not very interesting like response.....

 

Other, PS need a legend (problem in backoffice after uploading picture.

How can i fell the image_lang table ?

 

Regards

 

Thanks.

Regards.

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...