Title: Bug: CDN S3 Sync
Last modified: November 30, 2018

---

# Bug: CDN S3 Sync

 *  Resolved [Pratham](https://wordpress.org/support/users/pratham2003/)
 * (@pratham2003)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/bug-cdn-s3-sync/)
 * We have many such filters as follows that classify files into their own unique
   directories based on filename patterns.
 *     ```
       add_filter('wp_handle_upload_prefilter', 'icons_upload_filter' );
   
       function icons_upload_filter( $file ){
       		$is_icon = stripos($file['name'], 'icon-');
       		if( $is_icon !== false ){
       			add_filter('upload_dir', 'icons_post_upload_dir');
       		}
   
           return $file;
       }
   
       function icons_post_upload_dir($path){
       	$custom_dir = '/icons';
       	$path['path']    = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month)
       	$path['url']     = str_replace($path['subdir'], '', $path['url']);
       	$path['subdir']  = $custom_dir;
       	$path['path']   .= $custom_dir;
       	$path['url']    .= $custom_dir;
       	return $path;
       }
       ```
   
 * The issue is that when W3TC tries to sync files to S3 it uses the wrong path 
   and we end up seeing the following error.
    `wp-content/uploads/icon-ad1.png Source
   file not found.`
 * But when I check the path of the file in wp_posts or wp_postmeta we see the corrent
   URL.
    Screenshots:
 * > [View post on imgur.com](https://imgur.com/Esj6EfW)
 * > [View post on imgur.com](https://imgur.com/euA8PWy)
 * Is there a filter in W3TC we can use to correct the path while uploading to S3?
    -  This topic was modified 7 years, 8 months ago by [Pratham](https://wordpress.org/support/users/pratham2003/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/bug-cdn-s3-sync/#post-10941830)
 * Hello,
 * W3 Total Cache has a way to control paths it uses for uploaded files.
    `$files
   = apply_filters( 'w3tc_cdn_update_attachment', $files );` Your code modifies 
   wp behavior but written such a way that it doesn’t modify W3 Total Cache upload
   logic.
 *  Thread Starter [Pratham](https://wordpress.org/support/users/pratham2003/)
 * (@pratham2003)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/bug-cdn-s3-sync/#post-10960096)
 * Thanks!
 * I had assumed W3TC would use the paths found in wp_posts / wp_postmeta tables.
 * I’ll try this filter out.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Bug: CDN S3 Sync’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

## Tags

 * [cdn](https://wordpress.org/support/topic-tag/cdn/)
 * [s3](https://wordpress.org/support/topic-tag/s3/)

 * 2 replies
 * 2 participants
 * Last reply from: [Pratham](https://wordpress.org/support/users/pratham2003/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/bug-cdn-s3-sync/#post-10960096)
 * Status: resolved