We have a backend system where on a form fill, a PDF is generated - this PDF is then uploaded to dropbox and a link to the file is retrieved which is then added to the database and is visible to our vendors.
I have looked high and low - but the only way to get these links is using the createTemporaryDirectLink directive. However, these links are temporary and expire after a few hours.
I am looking to procure sharable non-expiring links.
Here is my current code that works fine
// Dropbox //
$dropbox_config = array(
'key' => 'xxxx',
'secret' => 'xxxx'
);
$accessToken='xxx-xxxxx';
$appInfo = dbx\AppInfo::loadFromJson($dropbox_config);
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$sqlQuery = "select dropboxLink from get_order where orderId='".$lastOrderId."'";
$rsGetDropLink = mysqli_query($dbLink,$sqlQuery);
$rowGetDropLink = mysqli_fetch_assoc($rsGetDropLink);
$f = fopen("Orders/".$rowGetDropLink['dropboxLink'].'.pdf', "rb");
$result = $dbxClient->uploadFile("/Orders/".$rowGetDropLink['dropboxLink'].'.pdf', dbx\WriteMode::add(), $f);
fclose($f);
print_r($result);
$file = $dbxClient->getMetadata("/Orders/".$rowGetDropLink['dropboxLink'].'.pdf');
$dropboxPath = $file['path'];
$pathError = dbx\Path::findError($dropboxPath);
if ($pathError !== null) {
fwrite(STDERR, "Invalid <dropbox-path>: $pathError\n");
die;
}
$link = $dbxClient->createTemporaryDirectLink($dropboxPath);
$dw_link = $link[0]."?dl=1";
$sqlQuery = "update get_order set fullDropboxLink='".$dw_link."' where orderId='".$lastOrderId."'";
mysqli_query($dbLink,$sqlQuery);
// Dropbox ends//
header("location: thankyou.php?ordId=".$lastOrderId.'&categoryId='.$_REQUEST['categoryId']);
As you can see, we use the createTemporaryDirectLink method which leads to a temporary link being fetched which expired overtime.
Our vendors check these files often every two days - so this is a non-usable solution.