/// <summary>
        /// Put file (size less than 1Mo) in the safebox.
        /// </summary>
        /// <param name="fileName">Required</param>
        /// <param name="fileTitle">Required and must be UNIQUE</param>
        /// <param name="fileCreator"></param>
        /// <param name="fileSubject"></param>
        /// <param name="fileDescription"></param>
        /// <param name="filePublisher"></param>
        /// <param name="fileType"></param>
        /// <param name="stream"></param>
        ///<returns>Unique Id to store.</returns>
        ///<remarks>null if K.O</remarks>

        public string WriteWS(string fileName,
                              string fileTitle,
                              string fileCreator,
                              string fileSubject,
                              string fileDescription,
                              string filePublisher,
                              string fileType,
                              FileStream stream)
        {
            if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(fileTitle))
            {
                throw new Exception("D3SError - WriteWS : fileName and fileTitle are required.");
            }

            Dictionary<string, string> toMetadatas = new Dictionary<string, string>();
            toMetadatas.Add("fileName", fileName);
            toMetadatas.Add("fileTitle", fileTitle);
            toMetadatas.Add("fileCreator", fileCreator);
            toMetadatas.Add("fileSubject", fileSubject);
            toMetadatas.Add("fileDescription", fileDescription);
            toMetadatas.Add("filePublisher", filePublisher);
            toMetadatas.Add("fileType", fileType);


            DictaoD3SStorage.Metadata[] Metadatas = _InitializeMetadatas(toMetadatas);

            GrantWrite pGrantWrite = new GrantWrite();
            pGrantWrite.applicantPath = this._D3SUser;
            pGrantWrite.containerPath = this._D3SSafeboxPath;

            try
            {
                GrantWriteResponseContent pGrantWriteResponseContent = this._ClientAuthority.grantWrite(pGrantWrite);
                //check authority
                if (pGrantWriteResponseContent.grantWriteResponse.securityToken != null && pGrantWriteResponseContent.grantWriteResponse.certificates != null)
                {
                    //Permission granted
                    Write pWrite = new Write();
                    pWrite.applicantPath = this._D3SUser;
                    pWrite.securityToken = new DictaoD3SStorage.SAMLToken();
                    pWrite.securityToken.Value = pGrantWriteResponseContent.grantWriteResponse.securityToken.Value;
                    pWrite.containerPath = this._D3SSafeboxPath;
                    pWrite.certificates = new DictaoD3SStorage.Certificates();
                    pWrite.certificates.Value = pGrantWriteResponseContent.grantWriteResponse.certificates.Value;
                    pWrite.metadatas = Metadatas;
                    pWrite.data = new byte[stream.Length];
                    stream.Read(pWrite.data, 0, Convert.ToInt32(stream.Length));
                    WriteResponse pWriteResponse = this._ClientStorage.write(pWrite);
                    if (pWriteResponse != null)
                    {
                        string resourcePath = pWriteResponse.resourcePath;
                        return _GetIdFromResourcePath(resourcePath);
                    }

                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                stream.Close();
            }

            return null;
        }
        /// <summary>
        /// Put file (size more than 1Mo) in the safebox.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileTitle">Required and must be UNIQUE</param>
        /// <param name="fileCreator"></param>
        /// <param name="fileSubject"></param>
        /// <param name="fileDescription"></param>
        /// <param name="filePublisher"></param>
        /// <param name="fileType"></param>
        /// <param name="stream"></param>
        ///<returns>Unique Id to store.</returns>
        ///<remarks>null if K.O</remarks>
        public string WriteInStreamingMode(string fileName,
                                           string fileTitle,
                                           string fileCreator,
                                           string fileSubject,
                                           string fileDescription,
                                           string filePublisher,
                                           string fileType,
                                           FileStream stream)
        {
            string postURL = string.Format("{0}/Upload", _Tenant.D3S_StorageURL); 

            if (string.IsNullOrEmpty(fileTitle))
            {
                throw new Exception("D3SError - WriteInStreamingMode : fileTitle is required.");
            }

            Dictionary<string, string> toMetadatas = new Dictionary<string, string>();
            toMetadatas.Add("fileName", fileName);
            toMetadatas.Add("fileTitle", fileTitle);
            toMetadatas.Add("fileCreator", fileCreator);
            toMetadatas.Add("fileSubject", fileSubject);
            toMetadatas.Add("fileDescription", fileDescription);
            toMetadatas.Add("filePublisher", filePublisher);
            toMetadatas.Add("fileType", fileType);


            DictaoD3SStorage.Metadata[] Metadatas = _InitializeMetadatas(toMetadatas);

            GrantWrite pGrantWrite = new GrantWrite();
            pGrantWrite.applicantPath = this._D3SUser;
            pGrantWrite.containerPath = this._D3SSafeboxPath;

            try
            {
                GrantWriteResponseContent pGrantWriteResponseContent = this._ClientAuthority.grantWrite(pGrantWrite);
                //check authority
                if (pGrantWriteResponseContent.grantWriteResponse.securityToken != null && pGrantWriteResponseContent.grantWriteResponse.certificates != null)
                {
                    //Permission granted

                    //read from file

                    byte[] data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                    stream.Close();

                    // Generate post objects
                    Dictionary<string, object> postParameters = new Dictionary<string, object>();
                    postParameters.Add("token", System.Text.Encoding.Default.GetString(pGrantWriteResponseContent.grantWriteResponse.securityToken.Value));
                    postParameters.Add("recipients", System.Text.Encoding.Default.GetString(pGrantWriteResponseContent.grantWriteResponse.certificates.Value));
                    string serializedMetadatas = _SerializeMetadatas(Metadatas);
                    postParameters.Add("metadatas", serializedMetadatas);
                    postParameters.Add("data", new FormUpload.FileParameter(data, fileName, fileType));

                    // Create request and receive response

                    HttpWebResponse webResponse = FormUpload.MultipartFormDataPost(postURL, postParameters, _CertificateKey);

                    ////Process response
                    StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                    string fullResponse = responseReader.ReadToEnd();
                    webResponse.Close();

                    //process Write responsemethod
                    D3SWriteStreamModeResult pResult = D3SWriteStreamModeResult.Init(fullResponse);
                    if (pResult.error == null && !string.IsNullOrEmpty(pResult.result))
                    {
                        string depot = pResult.result;
                        return _GetIdFromResourcePath(depot);
                    }

                }
            }
            catch (Exception ex)
            {
                throw new Exception("D3SError Write in streaming mode - " + ex.Message);
            }
            finally
            {
                stream.Close();
            }

            return null;

        }