CDN Sync Tool
[resolved] Uploading custom files with duplicate check (3 posts)

  1. Gary Pendergast
    Posted 4 years ago #

    I'm uploading some custom files to CloudFiles using Cst_Sync::process(), but this uploads the file regardless of if it's already on the CDN or not. Is it possible to check if the file exists before uploading it?

  2. Backie
    Plugin Contributor

    Posted 4 years ago #

    Well the way I dealt with the problem of checking if the file has been uploaded before was to create a MySQL table and store the data there and check that before calling Cst_Sync::process(). The only other way I can think of checking is fetching the file from CloudFiles.

  3. Gary Pendergast
    Posted 4 years ago #

    Thanks, this put me on the right track. For those having the same problem, here's how I solved it:

    $cdn = get_option("cst_cdn");
    $objCdn = Cdn_Provider::getProvider($cdn["provider"]);
    $container = $objCdn->getObject();
    try {
    	$tmp = $container->get_object( $file );
    catch( Exception $e ) {
    	Cst_Sync::process( $file );

    The first block sets up a connection to the CDN using your settings in CST admin.

    The $container->get_object() call doesn't retrieve the contents of the file, it just checks for the file's existence, and grabs info on the file if it does exist, so is suitable for checking for the existence of large files.

    If the file doesn't exist, it throws an exception, which means we need to upload the file.

    I've only tested this on CloudFiles, it probably won't work with other CDNs.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic