OCS API path to file



Hello everybody
I have a problem with my use of OCS API.
I try to create a new share with my php application. Everything seems to work fine if I try to share a folder but when I try with zip file I've an error 400 with the message "please specify a file or folder path"
see bellow a piece of my code

$post_data = "shareType=3&path=$this->CUSTOMER/$this->CAMPAIGN_NAME";
$ch = curl_init();
$url = "https://owncloud-solutions.cacom.fr/owncloud/ocs/v1.php/apps/files_sharing/api/v1/shares";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERPWD, 'login:mdp');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
foreach(array_unique($this->zips) as $zip) {
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
$output = curl_exec ($ch); // execute
curl_close ($ch);

It works! but if I try with that
$post_data = "shareType=3&path=$this->CUSTOMER/$this->CAMPAIGN_NAME/$this->_MYFILE";
where the file is zip as "TRC-VL-1994-2016_Decembre_CADEAUX-010.zip" it doesn't work!

I try since 2 days and I'm totaly lost


Try renaming the zip file to "a.zip" and try again.

Are there any special characters ? I see that "Decembre" doesn't have an accent in your paste, but does the real file has one ?

You should absolutely urlencode() your file names in the post data !


Hello PVinc81
Thanks for your answer
I've already tried to encode my path but it didn't work either and the curl php function encode already its variables if I use POST option
I tried too to set a header in set_opt to force the encoding as www-form-urlencoded
I've tried what you said about renaming zip file and it didn't work either
Info: the parent folder has some spaces in its name but when I share this folder, it' works with the spaces