I am trying to upload chunked files via the API. I have read several post about this but there does not seem to be a straight forward solution yet.
The problem code I have:
$fileName = (FILE PATH HERE);
set_time_limit(0);
$file = fopen($fileName,"rb");
$chunkedFile = '';
while(!feof($file))
{
$chunkedFile .= fread($file, 1024);
}
fclose($file);
$payload = base64_encode($chunkedFile);
$params = array(
'service' => 'rest',
'method' => 'LibraryMediaFileUpload',
'response' => RESPONSE,
'fileId' => NULL,
'checksum' => md5($payload),
'payload' => $payload
);
callService($params, true);
Produces this when the file is larger than the first chunk size:
( ! ) Fatal error: Uncaught exception ‘OAuthException2’ with message ‘Request failed with code 500: {“file”:{“id”:“863”,“offset”:5510872}}’ in C:\wamp\www\xibo_interface_beta\oauth-php\library\OAuthRequester.php on line 117
Any idea what exactly this error is telling me would be helpful.
I don’t believe the problem is within Xibo.
But I if anyone knows, maybe, why I am getting the error or how to get more info about it, feel free to comment.
Line 117 is:
throw new OAuthException2('Request failed with code ' . $result['code'] . ': ' . $result['body']);
In the following function of OAuthRequester.php:
function doRequest ( $usr_id = 0, $curl_options = array(CURLOPT_SSL_VERIFYPEER => 0, ), $options = array() )
{
$name = isset($options['name']) ? $options['name'] : '';
if (isset($options['token_ttl']))
{
$this->setParam('xoauth_token_ttl', intval($options['token_ttl']));
}
if (!empty($this->files))
{
// At the moment OAuth does not support multipart/form-data, so try to encode
// the supplied file (or data) as the request body and add a content-disposition header.
list($extra_headers, $body) = OAuthBodyContentDisposition::encodeBody($this->files);
$this->setBody($body);
$curl_options = $this->prepareCurlOptions($curl_options, $extra_headers);
}
$this->sign($usr_id, null, $name);
$text = $this->curl_raw($curl_options);
$result = $this->curl_parse($text);
if ($result['code'] >= 400)
{
throw new OAuthException2('Request failed with code ' . $result['code'] . ': ' . $result['body']);
}
// Record the token time to live for this server access token, immediate delete iff ttl <= 0
// Only done on a succesful request.
$token_ttl = $this->getParam('xoauth_token_ttl', false);
if (is_numeric($token_ttl))
{
$this->store->setServerTokenTtl($this->getParam('oauth_consumer_key',true), $this->getParam('oauth_token',true), $token_ttl);
}
return $result;
}
If I swap “throw” for “echo” online 117 the file uploads correctly and everything continues. But of course I get the error echoed to the screen:
exception 'OAuthException2' with message 'Request failed with code 500: {"file":{"id":"884","offset":5510872}}' in C:\wamp\www\xibo_interface_beta\oauth-php\library\OAuthRequester.php:118 Stack trace: #0 C:\wamp\www\xibo_interface_beta\index.php(781): OAuthRequester->doRequest('1') #1 C:\wamp\www\xibo_interface_beta\index.php(691): callService(Array, true) #2 C:\wamp\www\xibo_interface_beta\index.php(178): LibraryMediaFileUpload() #3 {main}