php - uploading files to BOX using v2 API -


i'm trying upload file box using curl, can create , view folders not upload file.

according documentation curl request is:

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

i'm using method:

public function put_file($filename, $name, $parent_id) { $url = $this->upload_url . '/files/content';  $attributes = array('name' => $name, 'parent' => array('id' => $parent_id)); $params = array('attributes' => json_encode($attributes), 'file' => "@".realpath($filename)); $headers = array("authorization: bearer ".$this->access_token);   $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_ssl_verifypeer, false); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $params); $response = curl_exec($ch);  curl_close($ch);   return json_decode($response, true); }  

the response is:

array ( [url] => https://upload.box.com/api/2.0/files/content [content_type] => text/html;charset=utf-8 [http_code] => 400 [header_size] => 243 [request_size] => 228 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.616644 [namelookup_time] => 0.004139 [connect_time] => 0.151089 [pretransfer_time] => 0.465782 [size_upload] => 331 [size_download] => 0 [speed_download] => 0 [speed_upload] => 204 [download_content_length] => 0 [upload_content_length] => 331 [starttransfer_time] => 1.466139 [redirect_time] => 0 [redirect_url] =>  [primary_ip] => 74.112.184.85 [certinfo] => array ( )  [primary_port] => 443 [local_ip] => 213.230.222.4 [local_port] => 52643 ) 

i've looked @ similar questions on cannot see what/where i'm going wrong.

the library i'm using boxphpapi

not ideal got working using shell_exec instead:

$cmd = "curl https://upload.box.com/api/2.0/files/content \ -h \"authorization: bearer $this->access_token\" -x post \ -f attributes='{\"name\":\"$filename\",\"parent\": {\"id\":\"$parent_id\"}}' \ -f file=@\"$filename\"";  shell_exec($cmd); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -