TinyMCE所见即所得编辑器-上传

时间:2020-03-06 10:39:54

标签: javascript tinymce

当前,我正在网站中使用TinyMCE所见即所得编辑器。所有功能都很好,例如格式化或上传图片。现在我想上传视频或其他文件!

用于媒体的菜单项不包含上传功能-我该如何自行开发此功能,或者可能进行配置? enter image description here

我当前的配置如下:

    tinymce.init({
    selector: 'textarea#content',
    images_upload_url: "/api/v1/Upload/Image",
    plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists wordcount imagetools textpattern help',
    toolbar: 'formatselect | bold italic strikethrough forecolor backcolor permanentpen formatpainter | link image media | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent | removeformat | addcomment',
    media_live_embeds: true,
    file_picker_types: 'file image media',
    file_browser_callback_types: 'file image media',
    file_picker_callback: function (cb, value, meta) {


        if (meta.filetype == 'file') {

        }

        if (meta.filetype == 'image') {
            var input = document.createElement('input');
            input.setAttribute('type', 'file');
            input.setAttribute('accept', 'image/*');


            input.onchange = function () {
                var file = this.files[0];

                var reader = new FileReader();
                reader.onload = function () {

                    var id = file.name.split(".")[0];
                    var blobCache = tinymce.activeEditor.editorUpload.blobCache;
                    var base64 = reader.result.split(',')[1];
                    var blobInfo = blobCache.create(id, file, base64);
                    blobCache.add(blobInfo);


                    cb(blobInfo.blobUri(), { title: file.name });
                };
                reader.readAsDataURL(file);
            };
            input.click();
        }

        if (meta.filetype == 'media') {
            var input = document.createElement('input');
            input.setAttribute('type', 'file');
            input.setAttribute('accept', 'media/*');


            input.onchange = function () {
                var file = this.files[0];

                var reader = new FileReader();
                reader.onload = function () {

                    var id = file.name;
                    var blobCache = tinymce.activeEditor.editorUpload.blobCache;
                    var base64 = reader.result.split(',')[1];
                    var blobInfo = blobCache.create(id, file, base64);
                    blobCache.add(blobInfo);
                    cb(blobInfo.blobUri(), { title: file.name });
                };
                reader.readAsDataURL(file);
            };
            input.click();
        }
    },
    automatic_uploads: true,
    external_media_list_url: "/js/myexternallist.js",
    image_list: "/api/v1/Upload/Images",
    color_cols: '5',
    media_poster: true,
    media_alt_source: true,
    height: 600,
    language: 'de',
    setup: function (editor) {
        editor.on('change',
            function () {
                editor.save();
            });
    }
});

}

我只需要上传视频。也许有人可以运行它?

0 个答案:

没有答案