Help with API "add file"

27380

I've got an application that is based on PHP 7.0 and that uses the API to collaborate.

The basic API connections work, I can read directories and create folders.

For example folder creation:

 

<?PHP$accesstoken='123';$xml='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><folder><name>Test HH2</name><description>Via API</description><accessInherited>1</accessInherited></folder>';$ch = curl_init();curl_setopt($ch, CURLOPT_URL,"instancename.highq.com/.../folders  curl_setopt($ch, CURLOPT_PROXY, "456");curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/xml; charset=utf-8','Authorization:Bearer '.$accesstoken));curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS,$xml);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close ($ch);echo $server_output;?>

 
But I can not manage the file upload.
 
I follow the API instruction here:
collaborate.highq.com/.../wikiHome.action

My code looks like this:

 

<?PHP$accesstoken='123';$file=file_get_contents('/path/testhh.txt');$fields = array('file' => $file, 'filename' => 'test2.txt');$ch = curl_init();curl_setopt($ch, CURLOPT_URL,"instancename.highq.com/.../content curl_setopt($ch, CURLOPT_PROXY, "456");curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','Authorization:Bearer '.$accesstoken));curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS , $fields);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close ($ch);echo($server_output);?>

 

The file “test2.txt” mentioned here exists, so that’s not the problem.  

But the resulting error is:

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><error><link>instancename.highq.com/.../ref><summary>Access denied</summary></error>

 
Could someone help me here?
 
Thx, Helmut

Parents
  • Hi Helmut, I would assume it does. From what I read, isn't that part of CURLFile, the preferred method, more so in 7. Like I said I don't touch PHP. You have to set boundaries if you are sending multiple form values. Only if you're sending just file contents can you get away with it, even then it's up to the server what it enforces. As a side, and for anyone experiencing this, if when you upload your file, the server "stores" it as an application/octet-stream, it's because you need to include the mime type in the multi-part form, as well as filename, and file data.
Reply
  • Hi Helmut, I would assume it does. From what I read, isn't that part of CURLFile, the preferred method, more so in 7. Like I said I don't touch PHP. You have to set boundaries if you are sending multiple form values. Only if you're sending just file contents can you get away with it, even then it's up to the server what it enforces. As a side, and for anyone experiencing this, if when you upload your file, the server "stores" it as an application/octet-stream, it's because you need to include the mime type in the multi-part form, as well as filename, and file data.
Children
No Data