diff --git a/remote_stream_wrapper.inc b/remote_stream_wrapper.inc
index 0bf560b..388b31b 100644
--- a/remote_stream_wrapper.inc
+++ b/remote_stream_wrapper.inc
@@ -69,6 +69,11 @@ class DrupalRemoteStreamWrapper implements DrupalStreamWrapperInterface {
     }
 
     $extension = '';
+
+    // Strip out any query arguments that may be part of the basename.
+    $matches = array();
+    preg_match('/^[^?]+/', basename($uri), $matches);
+
     $file_parts = explode('.', basename($uri));
 
     // Remove the first part: a full filename should not match an extension.
