Thursday, 8 August 2013

Error uploading file to Box.com

Error uploading file to Box.com

I am writing a PHP application which has to upload pdf files to my
enterprise Box.com account.
I am receiving 400 error (Invalid input parameters in request), but I
think everything is correct.
function upload( $doc ) {
if ( ! $this->access() )
$this->getAccess();
if ( ! is_readable($doc) )
return false;
$this->curl->clear();
// $this->curl->setUpload( true );
$this->curl->setMethod( 'POST' );
$this->curl->setHeaders( $this->_header() );
$this->curl->setValues( array(
'parent_id' => 0,
'filename' => '@'.$doc
));
$this->curl->exec( 'https://upload.box.com/api/2.0/files/content' );
echo '<pre>'; print_r($this->curl->getHeaders()); echo '</pre>';
echo '<pre>'; print_r($this->curl->getValues()); echo '</pre>';
$response = $this->curl->getResult(true);
echo "<pre>"; print_r($response); echo "</pre>"; exit;
}
Result:
POST /api/2.0/files/content HTTP/1.1
User-Agent: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8;
rv:22.0) Gecko/20100101 Firefox/22.0
Host: upload.box.com
Accept: */*
Authorization: Bearer .....
Content-Length: 89
Content-Type: application/x-www-form-urlencoded
Array
(
[parent_id] => 0
[filename] => @/Applications/XAMPP/xamppfiles/htdocs/MyFile.pdf
)
stdClass Object
(
[type] => error
[status] => 400
[code] => invalid_request_parameters
[help_url] => http://developers.box.com/docs/#errors
[message] => Invalid input parameters in request
[request_id] => ......
)
When I uncomment the line for making the cURL Uploading file the method is
changed from POST to PUT and then I receive error 405 Method Not Allowed.
According to the API documentation here
http://developers.box.com/docs/#files-upload-a-file I am sending
everything correctly.

No comments:

Post a Comment