Box api v2 upload file using php -


i have been working on box api. work file upload. here code:

$path = 'https://upload.box.com/api/2.0/files/content'; $method = 'post'; $headers = array('authorization bearer ' . $accesstoken); $attributes = array('name'=>$file_name, 'parent'=>array('id'=>0)); $body = array('attributes'=>json_encode($attributes), 'file'=>'@'.realpath($filepath)); $result = $this->post($path, $method, $body, $headers); 

and pass of post function:

function post($url,$method, $fields, $headers){     try {         $ch = curl_init();         curl_setopt($ch,curlopt_url, $url);         curl_setopt($ch, curlopt_httpheader, $headers);         curl_setopt($ch, curlopt_returntransfer, true);         curl_setopt($ch, curlopt_postfields, $fields);         curl_setopt($ch, curlopt_followlocation, true);         $response = curl_exec($ch);         $responsecode = curl_getinfo($ch, curlinfo_http_code);          if (false === $response) {             $errno = curl_errno($ch);             $errstr = curl_error($ch);         }         curl_close($ch);      } catch (exception $e) {         $response = $e->getmessage();     }      return $responsecode; } 

i 400 error using if add line $body = http_build_query($body, '', '&'); before calling post function i'll 405 error.

in both cases though upload not working. made sure pass actual path of file not relative path in case wondering.

i checked solutions this: https://github.com/golchha21/boxphpapi didn't work either.

any idea on issue , how fix it?

have attempted making same request in chrome plugin postman? not sure post function here command in curl

curl https://upload.box.com/api/2.0/files/content -h "authorization: bearer access_token" -x post -f attributes='{"name":"myfile.jpeg", "parent":{"id":"0"}}' -f file=@file_path


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -