CKEditor 5自定义图像上传适配器问题

时间:2019-03-17 06:32:25

标签: jersey ckeditor5

我遵循了guide创建的自定义上传器适配器。使用球衣休息服务,但是我无法上传任何图像。有人可以帮忙吗?

此外,我需要检索图像扩展名。可以做到吗?

html:

<textarea id="editor" name="content" class="form-control" rows="3" ></textarea> 
<script src="https://cdn.ckeditor.com/ckeditor5/12.0.0/classic/ckeditor.js"></script> 
<script src="https://cdn.ckeditor.com/ckeditor5/12.0.0/classic/translations/zh-cn.js"></script>

JavaScript loader.file.name始终返回空。

class MyUploadAdapter { 
        constructor(loader) { 
        this.loader = loader; 
    } 
    upload() { 
        return new Promise((resolve, reject) => { 
            var data = new FormData(); 
            data.append('upload', this.loader.file); 
            $.ajax({url: $.trim($("#txtContextPath").val()) + "/home/picture/upload-editor", 
                type: 'POST', data: data, processData: false, contentType: false, datatype: 'json', 
                success: function (response) { 
                    resolve(response); 
                }, 
                error: function (jqXHR, textStatus) { 
                    reject(textStatus + jqXHR.status + ":" + jqXHR.statusText); 
                } 
             }); 
        }); 
    } 
    abort() { 
        reject("Upload abort"); 
    } 
} 
function MyCustomUploadAdapterPlugin(editor) { 
    editor.plugins.get('FileRepository').createUploadAdapter = (loader) => { 
    // Configure the URL to the upload script in your back-end here! 
        alert(loader.file.name); // always undefined
        return new MyUploadAdapter(loader); 
    }; 
}

$(document).ready(function () {

    ClassicEditor.create(document.querySelector('#editor'), { 
        language: "zh-cn", 
        extraPlugins: [MyCustomUploadAdapterPlugin] 
    }).catch(error => { 
        console.log(error); 
    }); 
});

以下jersey rest服务提供的Java代码。从后端,我只能获得16字节长的输入流。在文件详细信息中也没有文件名或扩展名,文件详细信息仅具有值“上载”。

@POST
@Path("upload-editor")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String uploadEditor(@FormDataParam("upload") InputStream uploadedInputStream, @FormDataParam("upload") FormDataContentDisposition fileDetail) {...}

0 个答案:

没有答案