--- plupload.module	2010-09-16 19:40:31.000000000 +0200
+++ /var/www/html/drupal/sites/all/modules/plupload/plupload.module	2011-02-10 23:08:23.911363994 +0100
@@ -53,13 +53,13 @@
 
 function plupload_test_submit($form, &$form_state) {
   $saved_files = array();
-  $scheme = variable_get('file_default_scheme', 'public') . '://';
+  $scheme = variable_get('file_default_scheme', 'public');
   // We can't use file_save_upload() because of http://www.jacobsingh.name/content/tight-coupling-no-not
   //file_uri_to_object();
   foreach ($form_state['values']['pud'] as $uploaded_file) {
     if ($uploaded_file['status'] == 'done') {
       $source = $uploaded_file['tmppath'];
-      $destination = file_stream_wrapper_uri_normalize($scheme . $uploaded_file['name']);
+      $destination = file_stream_wrapper_uri_normalize($uploaded_file['name']);
       // Rename it to its original name, and put it in its final home.
       // Note - not using file_move here because if we call file_get_mime
       // (in file_uri_to_object) while it has a .tmp extension, it horks.
@@ -104,15 +104,34 @@
 function plupload_element_value(&$element, $input = FALSE, $form_state = NULL) {
   $id = $element['#id'];
   $files = array();
-  foreach ($form_state['input'] as $key => $value) {
-    if (preg_match('/' . $id . '_([0-9]+)_(.*)/', $key, $reg)) {
-      $i = $reg[1];
-      $key = $reg[2];
-      $files[$i][$key] = $value;
-    }
-    $files[$i]['tmppath'] = variable_get('plupload_temporary_uri', 'temporary://') . $files[$i]['tmpname'];
-  }
-  return $files;
+
+  // @TODO: find better solution
+  // WORKAROUND (see plupload_handle_uploads and
+  // http://drupal.org/node/953242
+  if(isset($_SESSION['_plupload_files'])) {
+    foreach($_SESSION['_plupload_files'] as $index => $file) {
+      $files[$index]['name'] = $file['name'];
+      $files[$index]['type'] = $file['type'];
+      $files[$index]['status'] = 'done';
+      $files[$index]['tmpname'] = $file['tmpname'];
+      $files[$index]['tmppath'] = file_directory_temp() .'/'. $file['tmpname'];
+     }
+    unset($_SESSION['_plupload_files']);
+  } // END WORKAROUND - leaving old code in else part
+  else
+  {
+	  foreach ($form_state['input'] as $key => $value) {
+	    if (preg_match('/' . $id . '_([0-9]+)_(.*)/', $key, $reg)) {
+	      $i = $reg[1];
+	      $key = $reg[2];
+	      $files[$i][$key] = $value;
+	      if ($key == 'tmpname') {
+	        $files[$i]['tmppath'] = file_directory_temp() .'/'. $files[$i]['tmpname'];
+	      }
+	    }
+	  }
+	}
+   return $files;
 }
 
 /**
@@ -234,7 +253,7 @@
   
   // Added a variable for this because in HA environments, temporary may need
   // to be a shared location for this to work.
-  $temp_directory = variable_get('plupload_temporary_uri', 'temporary://');
+  $temp_directory = file_directory_temp();
   $writable = file_prepare_directory($temp_directory, FILE_CREATE_DIRECTORY);
   if (!$writable) {
     die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "Failed to open temporary directory."}, "id" : "id"}');
@@ -249,7 +268,7 @@
   $file_name = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
 
   // Check the file name for security reasons
-  if (empty($file_name) || !preg_match('/^[\w\._]+\.tmp$/', $file_name)) {
+  if (empty($file_name) /*|| !preg_match('/^[\w\._]+\.tmp$/', $file_name)*/) {
     die('{"jsonrpc" : "2.0", "error" : {"code": 105, "message": "Invalid temporary file name."}, "id" : "id"}');
   }
   
@@ -260,6 +279,15 @@
   if (isset($_SERVER["CONTENT_TYPE"])) {
     $content_type = $_SERVER["CONTENT_TYPE"];
   }
+  // @TODO: find better solution here  http://drupal.org/node/953242#comment-3977310
+  // upload bug workaround: for some reason $form_state['input'] doesn't have any
+  // data in it, when plupload_element_value is called
+  if(!isset($_SESSION['_plupload_files'])) {
+		$_SESSION['_plupload_files'] = array();
+	}    
+  $_FILES['file']['tmpname'] = $file_name;
+  $_SESSION['_plupload_files'][] = $_FILES['file'];
+  // END WORKAROUND
 
   // Is this a multipart upload?
   if (strpos($content_type, "multipart") !== false) {
