diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php
index 85fa777aa2154fa2a237b4d72ee63f858f679d40..18ccee58b0762bbfec7f5d81a3f2af21d9341c0d 100644
--- a/htdocs/api/class/api_documents.class.php
+++ b/htdocs/api/class/api_documents.class.php
@@ -36,9 +36,8 @@ class Documents extends DolibarrApi
      * @var array   $DOCUMENT_FIELDS     Mandatory fields, checked when create and update object
      */
     static $DOCUMENT_FIELDS = array(
-        'name',
         'modulepart',
-        'file'
+        'filename'
     );
 
     /**
diff --git a/htdocs/core/lib/geturl.lib.php b/htdocs/core/lib/geturl.lib.php
index 808e4f0ef092b1a8c05a598315d4b9ebb95ea038..6f268fda3a7255d566b24ef866ddbb39cd390e7f 100644
--- a/htdocs/core/lib/geturl.lib.php
+++ b/htdocs/core/lib/geturl.lib.php
@@ -71,6 +71,7 @@ function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addhea
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT);
     curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT);
 
+    //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);	// PHP 5.5
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);		// We want response
     if ($postorget == 'POST')
     {
diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php
index 0ff33bc36c55c10763d6ec33157d9705ab9adccd..b180586aa916b91e6b74625631627da0750c00c7 100644
--- a/test/phpunit/RestAPIDocumentTest.php
+++ b/test/phpunit/RestAPIDocumentTest.php
@@ -28,6 +28,7 @@ global $conf,$user,$langs,$db;
 require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
 require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php';
 require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php';
+require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php';
 
 if (empty($user->id)) {
     echo "Load permissions for admin user nb 1\n";
@@ -141,40 +142,50 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase
 
         $url = $this->api_url.'/documents/?api_key='.$this->api_key;
 
-        $fileName = 'img250x20.png';
-        $filePath = dirname(__FILE__).'/'.$fileName;
-        $mimetype = dol_mimetype($filePath);
-
         echo __METHOD__.' Request POST url='.$url."\n";
 
-        // Send to existant directory
+        
+        // Send to non existant directory
+        
+        dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit');
+        
+        //$data = '{ "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "" }';
         $data = array(
-          'modulepart' => 'facture',
-          'file' => 'eeeeeee',
-          'refname' => 'AV1303-0003',
-          'name' => $fileName, // Name for destination
-          'mime' => $mimetype );
-
+            'filename'=>"mynewfile.txt",
+            'modulepart'=>"medias",
+            'ref'=>"",
+            'subdir'=>"tmpphpunit/tmpphpunit2",
+            'filecontent'=>"content text",
+            'fileencoding'=>""
+        );
+        
         $result = getURLContent($url, 'POST', $data, 1);
-
         echo __METHOD__.' Result for sending document: '.var_export($result, true)."\n";
         echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n";
-        $this->assertEquals($result['curl_error_no'], '');
-        $this->assertEquals($result['content'], 'true');
+        $object = json_decode($result['content'], true);
+        $this->assertNotNull($object, 'Parsing of json result must no be null');
+        $this->assertEquals('401', $object['error']['code']);
 
-        // Send to unexistant directory
+        
+        // Send to existant directory
+        
+        dol_mkdir(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit2');
+        
         $data = array(
-          'modulepart' => 'facture',
-          'file' => $cfile,
-          'name' => 'AV1303-0003STSEIUDEISRESIJLEU/'.$fileName, // Name for destination
-          'type' => $mimetype, );
+            'filename'=>"mynewfilethatwillfails.txt",
+            'modulepart'=>"medias",
+            'ref'=>"",
+            'subdir'=>"tmpphpunit/tmpphpunit2",
+            'filecontent'=>"content text",
+            'fileencoding'=>""
+        );
 
         $result2 = getURLContent($url, 'POST', $data, 1);
         echo __METHOD__.' Result for sending document: '.var_export($result2, true)."\n";
-        echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n";
-
-        $object = json_decode($result2['content'], true);
-        $this->assertNotNull($object, 'Parsing of json result must no be null');
-        $this->assertEquals('401', $object['error']['code']);
+        echo __METHOD__.' curl_error_no: '.$result2['curl_error_no']."\n";
+        $object2 = json_decode($result2['content'], true);
+        $this->assertNotNull($object2, 'Parsing of json result must no be null');
+        $this->assertEquals($result2['curl_error_no'], '');
+        $this->assertEquals($result2['content'], 'true');
     }
 }