簡體   English   中英

如何使用文件選擇器處理程序和images_upload_handler用tinymce上傳圖像

[英]How to upload image with tinymce using file picker handler and images_upload_handler

默認情況下,tinymce圖像沒有瀏覽按鈕,您可以在其中單擊並查看一個對話框以選擇圖像。 在我的代碼中,我試圖將圖像選擇器按鈕添加到tinymce,但發現很難將其與images_upload_handler結合使用。 最后,我如何使用成功回調來更新images_upload_base_path。

tinymce.init({
    ...
    images_upload_handler: function (blobInfo, success, failure) {
        var xhr, formData;

        xhr = new XMLHttpRequest();
        xhr.withCredentials = false;
        xhr.open('POST', "postAcceptor.php");

        xhr.onload = function() {
            var json;

            if (xhr.status != 200) {
                failure("HTTP Error: " + xhr.status);
                return;
            }

            json = JSON.parse(xhr.responseText);

            if (!json || typeof json.location != "string") {
                failure("Invalid JSON: " + xhr.responseText);
                return;
            }

            success(json.location);
        };

        formData = new FormData();
        formData.append('file', blobInfo.blob(), blobInfo.filename());

        xhr.send(formData);
    }
});

我不太明白為什么,但是對我來說, images_upload_handler不能正常工作... =(

改用file_picker_callback ,例如在我發現的以下示例中: https : file_picker_callback

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM