WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Gary Pendergast
    Member
    Posted 3 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
    Member
    Plugin Contributor

    Posted 3 years ago #

    Hi,
    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
    Member
    Posted 3 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"]);
    $objCdn->setAccessCredentials($cdn);
    $objCdn->login();
    $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