Index: src/wp-includes/rewrite-functions.php
===================================================================
--- src/wp-includes/rewrite-functions.php	(revision 34336)
+++ src/wp-includes/rewrite-functions.php	(working copy)
@@ -318,6 +318,18 @@
 			return $id;
 	}
 
+	// Most common upload location.
+	if ( false !== strpos( $url, 'wp-content/uploads/' ) ) {
+		return attachment_url_to_postid( $url );
+	}
+
+	// Check for other upload locations.
+	$upload_dir = wp_upload_dir();
+	$upload_path = parse_url( $upload_dir['baseurl'], PHP_URL_PATH );
+	if ( false !== strpos( $url, $upload_path ) ) {
+		return attachment_url_to_postid( $url );
+	}
+
 	// Check to see if we are using rewrite rules
 	$rewrite = $wp_rewrite->wp_rewrite_rules();
 
