IvoryCKEditorBundle uploadimage无法解析JSON Response

时间:2017-05-26 18:35:13

标签: javascript php json symfony ckeditor

我将Symfony 2 projekt与IvoryCKEditor集成到Sonata。还安装了几个CKEditor插件。我已经配置了基本图像上传,但我还需要管理拖放图像上传。

Uploadimage documentation表示配置uploadUrl属性。

config.extraPlugins = 'uploadimage';
config.uploadUrl = '/uploader/upload.php';

我的app/config/config.yml看起来像这样:

ivory_ck_editor:
    default_config: default
    configs:
        default:
            extraPlugins: "uploadimage,image2,uploadwidget,widget,widgetselection,lineutils,notificationaggregator,notification,filetools"
            uploadUrl: "/admin/sonata/media/media/upload?provider=sonata.media.provider.image&responseType=json"
            filebrowserBrowseRoute: admin_sonata_media_media_browser
            filebrowserImageBrowseRoute: admin_sonata_media_media_browser
            filebrowserImageBrowseRouteParameters:
                provider: sonata.media.provider.image
            filebrowserUploadRoute: admin_sonata_media_media_upload
            filebrowserUploadRouteParameters:
                provider: sonata.media.provider.file
            filebrowserImageUploadRoute: admin_sonata_media_media_upload
            filebrowserImageUploadRouteParameters:
                provider: sonata.media.provider.image
    plugins:
        image2:
            path:     "/ckeditor/plugins/image2/"
            filename: "plugin.js"
        uploadimage:
            path:     "/ckeditor/plugins/uploadimage/"
            filename: "plugin.js"
        uploadwidget:
            path:     "/ckeditor/plugins/uploadwidget/"
            filename: "plugin.js"
        widget:
            path:     "/ckeditor/plugins/widget/"
            filename: "plugin.js"
        widgetselection:
            path:     "/ckeditor/plugins/widgetselection/"
            filename: "plugin.js"
        lineutils:
            path:     "/ckeditor/plugins/lineutils/"
            filename: "plugin.js"
        notificationaggregator:
            path:     "/ckeditor/plugins/notificationaggregator/"
            filename: "plugin.js"
        notification:
            path:     "/ckeditor/plugins/notification/"
            filename: "plugin.js"
        filetools:
            path:     "/ckeditor/plugins/filetools/"
            filename: "plugin.js"

uploadUrl出现/admin/sonata/media/media/uploadprovider=sonata.media.provider.image&responseType=json错误时enter image description here

Location: plugins/filetools/plugin.js
Description: An error occurred when parsing the upload response. Text could not be parsed to JSON.
Additional data:
responseText: Upload response text.

JSON Response显然有问题,但文件上传到目录

我的问题是uploadUrl应该是什么样的?

1 个答案:

答案 0 :(得分:1)

uploadUrl必须包含处理文件上传的脚本网址。

因此,如果您使用uploadUrl之类的config.uploadUrl = '/uploader/upload.php', 您必须在服务器端创建JSON响应(upload.php文件)以允许ckeditor解析响应

请参阅http://docs.ckeditor.com/#!/guide/dev_file_upload上的示例。

{
    "uploaded": 1,
    "fileName": "foo.jpg",
    "url": "/files/foo.jpg"
}

您必须获取文件名和要在服务器上保存文件的特定网址,并创建相关的响应。

参见(java服务器端的例子):

out.println("{");
out.println(" \"uploaded\": 1,");
out.println("\"Filename\":" + "\"" + fileName+"\",");
out.println(" \"url\":" + "\"" + url +"\"" );
out.println("}");