We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
DloadJunior
4 years agoExplorer | Level 3
Expired Access Token
Hi all,
I'm currently working on Dropbox API to upload a backup file (.tar.gz) of 25GB - 27GB. Earlier the dropbox API was working fine with the long-lived access token.
Below are the ste...
DloadJunior
4 years agoExplorer | Level 3
Hi Greg-DB
Thank you for your quick response.
>>the name and version number of the platform and SDK/library you are using, if any
I'm not using SDK/library, I have made a curl function to send/receive the data from Dropbox API. I'm using the PHP Stream Wrapper class to upload and download the backup file. Below is the code snippet of the curl function
function __curl($url, $headers = '', $filepointer = '', $upload_size = 0, $post = '', $download_file = '', $ignore_errors = 0, $retry = false){
global $error, $l;
// Set the curl parameters.
$ch = curl_init($url);
if(!empty($headers)){
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
if(!empty($filepointer)){
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $filepointer);
curl_setopt($ch, CURLOPT_INFILESIZE, $upload_size);
}
if(!empty($post)){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
//curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(!empty($download_file)){
curl_setopt($ch, CURLOPT_FILE, $download_file);
}
// Get response from the server.
$resp = curl_exec($ch);
echo '<br />Resp: ';
r_print($resp);
echo '<br />Curl Error:';
$curl_error = curl_error($ch);
echo $curl_error;
$errno = curl_errno($ch);
r_print($errno);
$error_message = curl_strerror($errno);
r_print($error_message);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "HTTP_CODE: ".$http_code;
$result = json_decode($resp, true);
r_print($result);
if(!empty($result['error']) && empty($ignore_errors)){
if($result['error']['.tag'] == 'invalid_access_token'){
$error[$result['error']['.tag']] = $l['invalid_access_token'];
}elseif($result['error']['.tag'] == 'incorrect_offset'){
$error[$result['error']['.tag']] = 'Incorrect Offset';
}elseif($result['error'][$result['error']['.tag']]['.tag'] == 'insufficient_space'){
$error[$result['error'][$result['error']['.tag']]['.tag']] = $l['insufficient_space'];
}elseif(!empty($result['error'][$result['error']['.tag']]['.tag'])){
$error[] = $result['error'][$result['error']['.tag']]['.tag'];
}else{
$error[$result['error']['.tag']] = $result['error']['.tag'];
}
return false;
}
return $result;
}
function stream_write($data){
global $error;
if(!is_resource($this->wp)){
$this->wp = fopen($this->tpfile, 'w+');
}
//Initially store the data in a memory
fwrite($this->wp, $data);
$this->tmpsize += strlen($data);
$data_size = strlen($data);
// Are we already more than 4 MB ?
if($this->tmpsize >= 4194304){
rewind($this->wp);
//Call upload append function to write the data from PHP Memory stream to Dropbox
$this->upload_append($this->session_id, $this->wp, $this->tmpsize);
// Close the temp file and reset the variables
fclose($this->wp);
$this->wp = NULL;
$this->tmpsize = 0;
}
return $data_size;
}
// Dropbox API to upload
function upload_append($session_id, $filep, $data_size){
global $error;
$args = json_encode(array('cursor' => array('session_id' => $session_id,
'offset' => $this->offset),
'close' => false));
$upload_url = 'https://content.dropboxapi.com/2/files/upload_session/append_v2';
$headers = array('Authorization: Bearer '.$this->access_token,
'Dropbox-API-Arg: '.$args,
'Content-Type: application/octet-stream');
$resp = $this->__curl($upload_url, $headers, $filep, $data_size);
if(is_null($resp)){
$this->offset += $data_size;
return $data_size;
}
return false;
}
>>the steps to reproduce the issue, including relevant code snippet(s) and parameter value(s), but don't include any access or refresh token(s)
I guess the issue can be reproduced by uploading a file large in chunks of 4MB which could take more than 4hrs to complete
I have previously opened a ticket, in which you can find the error I'm receiving, below is the ticket id for the same:
Ticket #17124496
Awaiting your response.
Greg-DB
Dropbox Community Moderator
4 years agoThanks! I see that ticket was automatically closed after some time because you didn't reply to the message with a question we sent on June 7. Did you receive that message? If so, please reply to that by email to re-open that with support. Otherwise, you can open a new one here. Either way, please share the rest of the requested information so we can investigate.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!