diff --git a/module/lang/lang-en.json b/module/lang/lang-en.json
index ca2d7d11b3d4cf0efe55dc6d11a4c27137086335..835ceda8ca1b508a6525708b37099989db2ee979 100644
--- a/module/lang/lang-en.json
+++ b/module/lang/lang-en.json
@@ -202,6 +202,7 @@
         "" : "",
         "ERROR_WORKSPACE_NOT_LINKED_USER_GROUPS_WIDGET" : "The workspace is not linked to any group of users",
         "ERROR_CAPTCHA_VALIDATION_WIDGET" : "The validation of the captcha failed",
+        "ERROR_CREATION_WIDGET_FILE" : "Error while creating the widget file",
         "" : "",
         "FORM_FMW_FILE_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "fmw file",
         "FORM_ADDITIONAL_RESOURCES_PUBLICATION_WORKSPACE_LOAD_PROJECT_DIRECTORY" : "Additionnal resources",
diff --git a/module/lang/lang-fr.json b/module/lang/lang-fr.json
index 608d664c6e8780c3847bf3fad57dad32399d6caf..8dde45f8ccb1d7e3f31f1f650f7b4d1047419c5c 100644
--- a/module/lang/lang-fr.json
+++ b/module/lang/lang-fr.json
@@ -199,6 +199,7 @@
         "FORM_WIDGET_BTN_PUBLICATION_WORKSPACE_EDIT_WIDGET" : "Voir la fenêtre de traitement",
         "FORM_BUTTON_DOWNLOAD_WIDGET" : "Télécharger le widget",
         "FORM_BUTTON_DELETE_WIDGET" : "Supprimer le widget",
+        "ERROR_CREATION_WIDGET_FILE" : "Erreur pendant la création du fichier de widget",
         "" : "",
         "ERROR_WORKSPACE_NOT_LINKED_USER_GROUPS_WIDGET" : "Le traitement n'est lié à aucun groupe de l'utilisateur.",
         "ERROR_CAPTCHA_VALIDATION_WIDGET" : "La validation du captcha a échoué.",
diff --git a/web_service/ws/Workspaces.class.inc b/web_service/ws/Workspaces.class.inc
index 5bd38768a1ed2fcce80e069577856de1d98c07e5..aedeb6a0a23d85736f18b8da15fc2d0bb31508a6 100755
--- a/web_service/ws/Workspaces.class.inc
+++ b/web_service/ws/Workspaces.class.inc
@@ -317,25 +317,21 @@ class Workspaces extends GTF {
             $oWorkspace = new Workspace($this->aPath, $this->aValues, $this->aProperties, $this->oConnection);
             $oWorkspace->GET();
             $sWorkspace_key = $oWorkspace->aFields["key"];
-            // Emplacement des widgets
-            $sWidgetDirectory = $this->aProperties["vas_home"] . '/ws_data/gtf/widget';
-            $bError = False;
-            if (!is_dir($sWidgetDirectory)) {
-                if (!mkdir($sWidgetDirectory, 0777, true)) {
-                    $bError = True;
-                    $this->aFields['errorMessage'] = "Failed to create directory " . $sWidgetDirectory;
-                }
+            $this->aFields['workspace_key'] = $sWorkspace_key;
+            // Widget dans une page html.
+            $sWidgetHtml = '<!DOCTYPE html>' . PHP_EOL . '<html>' . PHP_EOL . '<head>' . PHP_EOL . '<title>Widget</title>' . PHP_EOL . '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . PHP_EOL . '<meta http-equiv="X-UA-Compatible" content="IE=edge">' . PHP_EOL . '</head>' . PHP_EOL . '<body>';
+            $sWidgetHtml .= $this->aValues['widgetFileContent'];
+            $sWidgetHtml .= '' . PHP_EOL . '</body>' . PHP_EOL . '</html>';
+            // Création du fichier du widget.
+            if (putFileContentInWsDataDir('gtf', 'widget', '', '', $sWorkspace_key . ".html", $sWidgetHtml) !== false) {
+                $aXmlRacineAttribute['status'] = 1;
+                $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']);
             }
-            if (!$bError) {
-                $this->aFields['workspace_key'] = $sWorkspace_key;
-                // Widget dans une page html.
-                $sWidgetHtml = '<!DOCTYPE html>' . PHP_EOL . '<html>' . PHP_EOL . '<head>' . PHP_EOL . '<title>Widget</title>' . PHP_EOL . '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . PHP_EOL . '<meta http-equiv="X-UA-Compatible" content="IE=edge">' . PHP_EOL . '</head>' . PHP_EOL . '<body>';
-                $sWidgetHtml .= $this->aValues['widgetFileContent'];
-                $sWidgetHtml .= '' . PHP_EOL . '</body>' . PHP_EOL . '</html>';
-                file_put_contents($this->aProperties["vas_home"] . '/ws_data/gtf/widget/' . $sWorkspace_key . ".html", $sWidgetHtml);
+            else {
+                $oError = new VitisError(17, 'ERROR_CREATION_WIDGET_FILE');
+                $aXmlRacineAttribute['status'] = 0;
+                $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']);
             }
-            $aXmlRacineAttribute['status'] = (int) !$bError;
-            $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']);
             return $sMessage;
         }
         if (!empty($this->aValues['mode']) && $this->aValues['mode'] == "import") {
@@ -380,48 +376,68 @@ class Workspaces extends GTF {
                 }
 
                 $aReturn = $this->genericPost($this->aProperties['schema_gtf'], 'workspace', $this->aProperties['schema_gtf'] . '.seq_common', 'workspace_id');
-                $oWorkspace = new Workspace($this->aPath, $this->aValues, $this->aProperties, $this->oConnection);
-                $oWorkspace->GET();
-                $sFilePathName = $this->aProperties['workspace_dir'] . "/" . $oWorkspace->aFields["workspace_id"] . "/fme/" . $_FILES['fmw_file']['name'][$i];
-                $sDirName = $this->aProperties['workspace_dir'] . "/" . $oWorkspace->aFields["workspace_id"];
-                // Si le répertoire existe déja : suppression.
-                if (is_dir($sDirName))
-                    clearDir($sDirName);
-                //
-                mkdir($sDirName, 0777, true);
-                mkdir($sDirName . "/form", 0777, true);
-                mkdir($sDirName . "/form/ressources", 0777, true);
-                mkdir($sDirName . "/fme", 0777, true);
-
-                if (!move_uploaded_file($_FILES['fmw_file']['tmp_name'][$i], utf8_decode($sFilePathName))) {
-                    writeToErrorLog(ERROR_0031 . $_FILES['file']['name']);
-                    $aReturn = array(sStatus => 1, sMessage => WORKSPACE_ERROR_COPYING_FILE);
-                } else {
-                    // Fichier .fmw original en .bak.
-                    copy($sDirName . "/fme/" . utf8_decode($this->aValues['fmw_file']), $sDirName . "/fme/" . utf8_decode($this->aValues['fmw_file']) . '.bak');
-                    //
-                    fclose(fopen($sDirName . "/form/ressources/Subform.js", "w+"));
-                    fclose(fopen($sDirName . "/form/ressources/Subform.css", "w+"));
-                    $oFmwParser = new GtfFmwParser($sDirName . "/fme/" . $_FILES['fmw_file']['name'][$i]);
-                    // Sauve le .fmw sans les visualizers.
-                    $oFmwParser->save($sDirName . "/fme/" . utf8_decode($this->aValues['fmw_file']));
-                    // Création des formulaires json.
-                    $aJson = $oFmwParser->productJson($this->aProperties, $oWorkspace->aFields["name"]);
-                    $fJson = fopen($sDirName . "/form/Subform.json", "w+");
-                    if (fwrite($fJson, json_encode($aJson)) == FALSE) {
-                        if ($fJson == FALSE) {
-                            writeToErrorLog("Subform.json can't be opened : " . $sDirName . "/form/ressources/Subform.json" . "(Workspaces.class.inc : verify the property workspace_dir)");
-                        } else {
-                            writeToErrorLog("Subform.json can't be writed : " . $sDirName . "/form/ressources/Subform.json" . "(Workspaces.class.inc : verify the folder's rights)");
+                if ($aReturn['sStatus'] == 1) {
+                    $oWorkspace = new Workspace($this->aPath, $this->aValues, $this->aProperties, $this->oConnection);
+                    $oWorkspace->GET();
+                    $sFilePathName = $this->aProperties['workspace_dir'] . "/" . $oWorkspace->aFields["workspace_id"] . "/fme/" . $_FILES['fmw_file']['name'][$i];
+                    $sDirName = $this->aProperties['workspace_dir'] . "/" . $oWorkspace->aFields["workspace_id"];
+                    // Si le répertoire existe déja : suppression.
+                    deleteDirectoryInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], '', '');
+                    // Upload du fichier fmw.
+                    $this->aValues['fme'] = $this->aValues['fmw_file'];
+                    $_FILES['fme'] = array(
+                        'name' => $_FILES['fmw_file']['name'][$i],
+                        'type' => $_FILES['fmw_file']['type'][$i],
+                        'tmp_name' => $_FILES['fmw_file']['tmp_name'][$i],
+                        'error' => $_FILES['fmw_file']['error'][$i],
+                        'size' => $_FILES['fmw_file']['size'][$i]
+                    );
+                    $sErrorMessage = uploadInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], "fme", $this->aValues, -1, "fmw");
+                    if (!empty($sErrorMessage)) {
+                        writeToErrorLog($sErrorMessage);
+                        $oError = new VitisError(8, $sErrorMessage);
+                        $aXmlRacineAttribute['status'] = 0;
+                        $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']);
+                    } else {
+                        // Copie du .fmw original en .bak.
+                        copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'][$i], $_FILES['fmw_file']['name'][$i] . '.bak');
+                        // Création des fichiers vides de ressources js et css.
+                        createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js');
+                        createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css');
+                        // Télécharge le fichier .fmw qui est sur S3.
+                        if ($this->aProperties['fileS3Uploader'] === true) {
+                            $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $_FILES['fmw_file']['name'][$i]);
+                            if ($sFmwFileContent !== false) {
+                                $sFmwFilePath = $this->aProperties['extract_dir'] . '/' . getUniqRandomId() . '/' . $_FILES['fmw_file']['name'][$i];
+                                mkdir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
+                                file_put_contents($sFmwFilePath, $sFmwFileContent);
+                            }
                         }
+                        else
+                            $sFmwFilePath = $sDirName . "/fme/" . $_FILES['fmw_file']['name'][$i];
+                        // Sauve le .fmw sans les visualizers.
+                        $oFmwParser = new GtfFmwParser($sFmwFilePath);
+                        $oFmwParser->save($sFmwFilePath);
+                        // Sauve le fichier sur S3.
+                        if ($this->aProperties['fileS3Uploader'] === true)
+                            putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'][$i], file_get_contents($sFmwFilePath));
+                        // Création des formulaires json.
+                        $aJson = $oFmwParser->productJson($this->aProperties, $oWorkspace->aFields["name"]);
+                        if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', json_encode($aJson)) !== false) {
+                            copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'WSubform.json');
+                            copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'DSubform.json');
+                        }
+                        $oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]);
+                        // Supprime le fichier .fmw temporaire.
+                        if ($this->aProperties['fileS3Uploader'] === true)
+                            clearDir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
+                        //
+                        $this->aValues["errorkeys"] = "";
                     }
-                    fclose($fJson);
-                    copy($sDirName . "/form/Subform.json", $sDirName . "/form/WSubform.json");
-                    copy($sDirName . "/form/Subform.json", $sDirName . "/form/DSubform.json");
-                    $oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]);
-                    $this->aValues["errorkeys"] = "";
+                    $sMessage = $aReturn['sMessage'];
                 }
-                $sMessage = $aReturn['sMessage'];
+                else
+                    return $aReturn['sMessage'];
             }
         } else {
             $this->aValues["fmw_file"] = $_FILES['fmw_file']['name'];
@@ -508,53 +524,58 @@ class Workspaces extends GTF {
                                 $_FILES['fme'] = $_FILES['fmw_file'];
                                 $sErrorMessage = uploadInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], "fme", $this->aValues, -1, "fmw");
                                 // Copie du .fmw original en .bak.
-                                if (empty($sErrorMessage))
-                                    copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], $_FILES['fmw_file']['name'] . '.bak');
-                                else
+                                if (!empty($sErrorMessage)) {
                                     writeToErrorLog($sErrorMessage);
-                                // Création des fichiers vides de ressources js et css.
-                                createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js');
-                                createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css');
-                                // Upload du fichier de ressource.
-                                if ($this->aValues["comp_file"] != "") {
-                                    $this->aValues['fme'] = $this->aValues['comp_file'];
-                                    $_FILES['fme'] = $_FILES['comp_file'];
-                                    $sErrorMessage = uploadInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], "fme", $this->aValues);
-                                    /*
-                                    $ext = pathinfo($_FILES['comp_file']['name'], PATHINFO_EXTENSION);
-                                    if ($ext == "zip") {
-                                        unZip($sDirName . "/fme/" . utf8_decode($_FILES['comp_file']['name']), $sDirName . "/fme/");
-                                    }
-                                    */
+                                    $oError = new VitisError(8, $sErrorMessage);
+                                    $aXmlRacineAttribute['status'] = 0;
+                                    $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']);
                                 }
-                                // Télécharge le fichier .fmw qui est sur S3.
-                                if ($this->aProperties['fileS3Uploader'] === true) {
-                                    $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $_FILES['fmw_file']['name']);
-                                    if ($sFmwFileContent !== false) {
-                                        $sFmwFilePath = $this->aProperties['extract_dir'] . '/' . getUniqRandomId() . '/' . $_FILES['fmw_file']['name'];
-                                        mkdir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
-                                        file_put_contents($sFmwFilePath, $sFmwFileContent);
+                                else {
+                                    copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], $_FILES['fmw_file']['name'] . '.bak');
+                                    // Création des fichiers vides de ressources js et css.
+                                    createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.js');
+                                    createEmptyFileInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form/ressources', 'Subform.css');
+                                    // Upload du fichier de ressource.
+                                    if ($this->aValues["comp_file"] != "") {
+                                        $this->aValues['fme'] = $this->aValues['comp_file'];
+                                        $_FILES['fme'] = $_FILES['comp_file'];
+                                        $sErrorMessage = uploadInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], "fme", $this->aValues);
+                                        /*
+                                        $ext = pathinfo($_FILES['comp_file']['name'], PATHINFO_EXTENSION);
+                                        if ($ext == "zip") {
+                                            unZip($sDirName . "/fme/" . utf8_decode($_FILES['comp_file']['name']), $sDirName . "/fme/");
+                                        }
+                                        */
                                     }
+                                    // Télécharge le fichier .fmw qui est sur S3.
+                                    if ($this->aProperties['fileS3Uploader'] === true) {
+                                        $sFmwFileContent = getFileContentInWsDataDir("gtf", "workspace", $this->aValues["my_vitis_id"], $sField = 'fme', $_FILES['fmw_file']['name']);
+                                        if ($sFmwFileContent !== false) {
+                                            $sFmwFilePath = $this->aProperties['extract_dir'] . '/' . getUniqRandomId() . '/' . $_FILES['fmw_file']['name'];
+                                            mkdir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
+                                            file_put_contents($sFmwFilePath, $sFmwFileContent);
+                                        }
+                                    }
+                                    else
+                                        $sFmwFilePath = $sDirName . "/fme/" . $_FILES['fmw_file']['name'];
+                                    // Sauve le .fmw sans les visualizers.
+                                    $oFmwParser = new GtfFmwParser($sFmwFilePath);
+                                    $oFmwParser->save($sFmwFilePath);
+                                    // Sauve le fichier sur S3.
+                                    if ($this->aProperties['fileS3Uploader'] === true)
+                                        putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], file_get_contents($sFmwFilePath));
+                                    // Création des formulaires json.
+                                    $aJson = $oFmwParser->productJson($this->aProperties, $oWorkspace->aFields["name"]);
+                                    if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', json_encode($aJson)) !== false) {
+                                        copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'WSubform.json');
+                                        copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'DSubform.json');
+                                    }
+                                    $oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]);
+                                    // Supprime le fichier .fmw temporaire.
+                                    if ($this->aProperties['fileS3Uploader'] === true)
+                                        clearDir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
+                                    /*                         * ************************************************************** */
                                 }
-                                else
-                                    $sFmwFilePath = $sDirName . "/fme/" . $_FILES['fmw_file']['name'];
-                                // Sauve le .fmw sans les visualizers.
-                                $oFmwParser = new GtfFmwParser($sFmwFilePath);
-                                $oFmwParser->save($sFmwFilePath);
-                                // Sauve le fichier sur S3.
-                                if ($this->aProperties['fileS3Uploader'] === true)
-                                    putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'fme', $_FILES['fmw_file']['name'], file_get_contents($sFmwFilePath));
-                                // Création des formulaires json.
-                                $aJson = $oFmwParser->productJson($this->aProperties, $oWorkspace->aFields["name"]);
-                                if (putFileContentInWsDataDir('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', json_encode($aJson)) !== false) {
-                                    copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'WSubform.json');
-                                    copyFileInWsDataDir ('gtf', 'workspace', $this->aValues["my_vitis_id"], 'form', 'Subform.json', 'DSubform.json');
-                                }
-                                $oFmwParser->updateMetadata($this->oConnection->oBd, $oWorkspace->aFields["workspace_id"]);
-                                // Supprime le fichier .fmw temporaire.
-                                if ($this->aProperties['fileS3Uploader'] === true)
-                                    clearDir(pathinfo($sFmwFilePath, PATHINFO_DIRNAME));
-                                /*                         * ************************************************************** */
                             } else {
                                 writeToErrorLog("the uploaded file is not a fmw file or no file uploaded (Workspaces.class.inc : user_id->" . $_SESSION["user_id"] . ")");
                                 $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']);
@@ -564,6 +585,11 @@ class Workspaces extends GTF {
                         $sMessage = $aReturn['sMessage'];
                 }
             }
+            else {
+                $oError = new VitisError(1, 'REQUEST_ERROR');
+                $aXmlRacineAttribute['status'] = 0;
+                $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']);
+            }
         };
         return $sMessage;
     }