diff --git a/js/ng_plupload.js b/js/ng_plupload.js
index e5b89c2..83dfe03 100644
--- a/js/ng_plupload.js
+++ b/js/ng_plupload.js
@@ -4,7 +4,9 @@
     attach: function (context, settings) {
       $(".plupload-element", context).once('ng_plupload-init', function () {
         $(this).pluploadQueue().bind('BeforeUpload', function(up, file){
-        up.settings.url = up.settings.url.split('?filename')[0] + '?filename='+file.name;
+        // Remove any previous filename query strings and append the next one.
+        up.settings.url = up.settings.url.replace(/([?&])filename=[^&]+/, '');
+        up.settings.url += (up.settings.url.match(/[?]/) ? '&filename=' : '?filename=') + file.name;
       });
     });
   }
