我将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
错误时
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
应该是什么样的?
答案 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("}");