function McUploaderViaServer($rootScope, uploadOptions) {
    "use strict";

    var _uin           = null;
    var _filesInfo     = null;
    var fVisualisation = null;
    var Self           = this;
    var UPLOAD         = 1;
    var PREPARING      = 4;
    var pastView       = null;

    function __sendFileMessage(info, allok) {
        // uploadOptions.done(
        //     info.chatType,
        //     info.ID,
        //     info.Hash + mcConst.CRLF + info.FileName + mcConst.CRLF + mcService.fileTimeStamp(info.lastModifiedDate) +
        //                 mcConst.CRLF + info.fileSize + mcConst.CRLF + (info.resolution ? info.resolution : "-") +
        //                 (info.cText ? (mcConst.CRLF + info.cText) : ""), // excel = cText is not empty
        //     info.Type
        // );

        uploadOptions.done(
            info.chatType,
            info.ID,
            JSON.stringify({
                Hash        : info.Hash,
                FileName    : info.FileName,
                UTCWriteTime: mcService.fileTimeStamp(info.lastModifiedDate),
                Size        : info.fileSize,
                Resolution  : info.resolution ? info.resolution : "-",
                Desc        : info.cText ? info.cText : ""
            }),
            info.Type
        );

        fVisualisation._hideProgressInfo(allok);
    }
    function __setUIN(uin, _type) {
        if (_type === $rootScope.chatAliases.UIN) {
            _uin = uin;
        }
    }
    function __getUIN() {
        return _uin;
    }
    function __clearUIN() {
        _uin = null;
        _filesInfo = null;

        fVisualisation.abortTransfer();
    }
    function __onBeforeFileAdd() {
        if (uploadOptions.onBeforeFileAdd && uploadOptions.onBeforeFileAdd.apply(null, arguments)){
            __clearUIN();
        } else {
            fVisualisation._showProgressInfo(PREPARING, true);
        }
    }
    function __getFilesInfo() {
        return _filesInfo;
    }
    function __onAfterFileAdd() {
        if (uploadOptions.onAfterFileAdd && uploadOptions.onAfterFileAdd.apply(null, arguments)){
            __clearUIN();
        } else {
            fVisualisation._showProgressInfo(UPLOAD);
        }
    }
    function __onBeforeUpload(hash) { // todo: upload list

    }
    function __doUploadImage(_ID, type, image, resolution, cText) {
        __setUIN(_ID, type);

        $rootScope.$broadcast(window._messages_.mcFileUploader.uploadFile, [
            function error() { // info
                fVisualisation._hideProgressInfo();

                __clearUIN();

                webix.alert('Error file uploading!');
            },
            function success() { // file
                var info = this;

                __clearUIN();

                // info.Type       = cText === void(0) ? mcConst._CMD_.msgType.IMAGE_NEW : mcConst._CMD_.msgType.CLIPBOARD_EXCEL;
                info.Type       = mcConst._CMD_.msgType.IMAGE_NEW; // todo: добавить обработку CLIPBOARD_EXCEL для нового типа сообщений
                info.chatType   = type;
                info.ID         = _ID;
                info.fileSize   = image.size;
                info.resolution = resolution;
                info.cText      = cText;

                if (info.FileName === "image.png"){
                    info.FileName = "image_" + (new Date()).getTime() + ".png";
                }

                __sendFileMessage(info);
            }, {
                onBeforeFileAdd  : __onBeforeFileAdd,
                onPrepareProgress: fVisualisation._onPrepareProgress,
                onAfterFileAdd   : __onAfterFileAdd,
                uploadProgress   : fVisualisation.getUploadProgress(),

                clipboardImage   : image, // Получаем файл как Blob (бинарные данные)
                Where            : mcService.getCurrentChantTypeForFiles($rootScope.GetChatType()),
                ID               : _ID
            }
        ]);
    }
    function __onPastFile(e) {
        if (!fVisualisation.getState() && (
            ((mcService.checkRights(mcConst._CMD_.RS.QTxtConfSendFiles) || mcService.checkRights(mcConst._CMD_.RS.QSendImages))     && $rootScope.GetChatType() === $rootScope.chatAliases.UID) ||
            ((mcService.checkRights(mcConst._CMD_.RS.QPrivInsertFiles)  || mcService.checkRights(mcConst._CMD_.RS.QImagesPrivates)) && $rootScope.GetChatType() === $rootScope.chatAliases.UIN)
        )) {
            var type    = $rootScope.GetChatType();
            var cText   = "";
            var imgInfo = [];

            // if (e.clipboardData.items.length) {
            //     for (var i = e.clipboardData.items.length - 1; i >= 0; i--) {
            //         if (e.clipboardData.items[i].kind === "file" && e.clipboardData.items[i].type === "image/png") {
            //             e.preventDefault();
            //
            //             Promise.all(Array.prototype.map.call(e.clipboardData.items, function (item){
            //                 if (item.kind === "string" && item.type === "text/plain"){
            //                     return item.getAsString(function (txt){
            //                         cText = txt
            //                     });
            //                 } else
            //                 if (item.kind === "file" && (item.type === "image/png" || item.type === "image/jpg" || item.type === "image/jpeg") ){
            //                     return new Promise(function (resolve){
            //                         var image   = item.getAsFile();
            //                         var _ID     = $rootScope.GetChatID();
            //                         var tempImg = document.createElement("img");
            //
            //                         tempImg.src = window.URL.createObjectURL(image);
            //
            //                         tempImg.onload = function () {
            //                             var resolution = tempImg.width + "x" + tempImg.height;
            //                             tempImg.src = "";
            //                             tempImg     = null;
            //
            //                             if (Self.pastImagePreview) {
            //                                 Self.pastImagePreview(image, function () { // comment
            //                                     imgInfo = [_ID, type, image, resolution];
            //
            //                                     resolve();
            //                                 });
            //                             } else {
            //                                 imgInfo = [_ID, type, image, resolution];
            //
            //                                 resolve();
            //                             }
            //                         };
            //                     })
            //                 }
            //             }))
            //             .then(function (){
            //                 __doUploadImage.apply(null, imgInfo.concat(cText ? [cText] : []));
            //             })
            //             .catch(function (err){
            //                 console.error(err.messsage);
            //             });
            //
            //             break;
            //         } else
            //         if (e.clipboardData.items[i].kind === "file" && e.clipboardData.files[i].size) {
            //
            //         }
            //     }
            // } else

            if (e.clipboardData.files.length) {
                e.preventDefault();

                // если в буфере 1 файл, но несколько итемов - то это скрин из экселя со скопированным тестом таблички
                if (e.clipboardData.files.length === 1 && 
                    (e.clipboardData.files[0].type === "image/png" || e.clipboardData.files[0].type === "image/jpg" || e.clipboardData.files[0].type === "image/jpeg")) {

                    Promise.all(Array.prototype.map.call(e.clipboardData.items, function (item){
                        if (item.kind === "string" && item.type === "text/plain"){
                            return item.getAsString(function (txt){
                                cText = txt
                            });
                        } else
                        if (item.kind === "file" && (item.type === "image/png" || item.type === "image/jpg" || item.type === "image/jpeg") ){
                            return new Promise(function (resolve){
                                var image   = item.getAsFile();
                                var _ID     = $rootScope.GetChatID();
                                var tempImg = document.createElement("img");

                                tempImg.src = window.URL.createObjectURL(image);

                                tempImg.onload = function () {
                                    var resolution = tempImg.width + "x" + tempImg.height;
                                    tempImg.src = "";
                                    tempImg     = null;

                                    if (Self.pastImagePreview) {
                                        Self.pastImagePreview(image, function () { // comment
                                            imgInfo = [_ID, type, image, resolution];

                                            resolve();
                                        });
                                    } else {
                                        imgInfo = [_ID, type, image, resolution];

                                        resolve();
                                    }
                                };
                            })
                        }
                    }))
                    .then(function (){
                        __doUploadImage.apply(null, imgInfo.concat(cText ? [cText] : []));
                    })
                    .catch(function (err){
                        console.error(err.messsage);
                    });
                } else
                if (e.clipboardData.files.length >= 1) {
                    Self._uploadFile(mcConst._CMD_.msgType.FILE_NEW, true, e.clipboardData);
                }
            }/* else

            if (e.clipboardData.files.length >= 0) {
                if (fVisualisation.getState()) {
                    webix.message(mcLang(601)); // "601":"Подождите окончания приема/передачи файлов",
                } else

                if (!$rootScope.isWebClient) {
                    if (Self.pastFilePreview){
                        Self.pastFilePreview(e.clipboardData.files, function () {
                            $rootScope.$broadcast(window._messages_.clientData.sendCMDToElectron, [
                                mcConst._CMD_.ce_get_clipboard_files_list
                            ]);
                        })
                    } else {
                        $rootScope.$broadcast(window._messages_.clientData.sendCMDToElectron, [
                            mcConst._CMD_.ce_get_clipboard_files_list
                        ]);
                    }
                }
            }*/
        }
    }

    this.getFilesInfo     = __getFilesInfo;
    this.getUINsend       = __getUIN;
    this.setUINsend       = __setUIN;
    this.abortUploading   = __clearUIN;
    this.sendFileMessage  = __sendFileMessage;
    this.pastImagePreview = null;
    this.pastFilePreview  = null;

    this.removePasteView  = function () {
        if (pastView) {
            pastView.removeEventListener("paste", __onPastFile);
        }
    };

    this._onPasteItemFromClipboard = function (_view){
        pastView = _view;

        pastView.addEventListener("paste", __onPastFile);
    };

    this.setVisualisation = function (_visualisation) {
        fVisualisation = _visualisation;
    };

    this._uploadFile      = function (fileType, filePath, dropFileInfo){
        function _DD_upload(_fileType, _filePath, _dropFileInfo, _currentID, _chatType) {
            __setUIN(_currentID, _chatType);

            $rootScope.$broadcast(window._messages_.mcFileUploader.uploadFile, [
                function error(){
                    fVisualisation._hideProgressInfo();

                    __clearUIN();

                    webix.alert('Error file uploading!');
                },
                function success(){
                    var info = this;

                    if (info.fileIdx === info.dropFile.files.length){
                        __clearUIN();
                    }

                    switch (_fileType){
                        case mcConst._CMD_.msgType.IMAGE_NEW:
                        // case mcConst._CMD_.msgType.IMAGE:
                            __sendFileMessage(info);
                        break;

                        default:
                            __sendFileMessage(info, true);
                    }
                }, {
                    onBeforeFileAdd     : __onBeforeFileAdd,
                    onAfterFileAdd      : __onAfterFileAdd,
                    onBeforeUpload      : __onBeforeUpload,
                    onPrepareProgress   : fVisualisation._onPrepareProgress,
                    uploadProgress      : fVisualisation.getUploadProgress(),

                    filePath: _filePath,
                    chatType: _chatType,
                    dropFile: _dropFileInfo,

                    Type  : _fileType,
                    Where : mcService.getCurrentChantTypeForFiles($rootScope.GetChatType()),
                    ID    : _currentID
                }
            ]);

            if (!$rootScope.isWebClient) {
                $rootScope.$broadcast(window._messages_.mcStatistics.setStatValue, [_dropFileInfo ? "n_file_drag" : "n_file", 1, false]); // false - увеличить значение на "1"
            }
        }

        var currentID = $rootScope.GetChatID();
        var chatType  = $rootScope.GetChatType();

        if (dropFileInfo && (mcConst.ClientSettings && mcConst.ClientSettings.PreviewDropFile)) {
            if (dropFileInfo.items.length === 1 && dropFileInfo.items[0].kind === "file" && Self.pastImagePreview &&
                (
                    dropFileInfo.items[0].type === "image/png" ||
                    dropFileInfo.items[0].type === "image/jpg" ||
                    dropFileInfo.items[0].type === "image/jpeg"||
                    dropFileInfo.items[0].type === "image/gif"
                ))
            {
                var image      = dropFileInfo.items[0].getAsFile();
                var resolution = "";
                var tempImg    = document.createElement("img");

                tempImg.src    = window.URL.createObjectURL(image);
                tempImg.onload = function () {
                    resolution   = tempImg.width + "x" + tempImg.height;
                    tempImg.src  = "";
                    tempImg      = null;

                    if (Self.pastImagePreview){
                        Self.pastImagePreview(image, function () {
                            __doUploadImage(currentID, chatType, image, resolution);
                        });
                    } else {
                        __doUploadImage(currentID, chatType, image, resolution);
                    }
                }
            } else
            if (Self.pastFilePreview) {
                var list = [];

                for (var i=0; i < dropFileInfo.files.length; i++){
                    list.push(dropFileInfo.files[i].name);
                }

                var dd = { files: mcService.Marge({ length : dropFileInfo.files.length }, dropFileInfo.files) };

                Self.pastFilePreview(list, function () {
                    _DD_upload(fileType, filePath, dd, currentID, chatType);
                });
            } else {
                _DD_upload(fileType, filePath, dropFileInfo, currentID, chatType);
            }
        } else {
            _DD_upload(fileType, filePath, dropFileInfo, currentID, chatType);
        }
    };
}