如何使用 Jodit uploader 和 coldfusion 上传图片?
How to upload image with Jodit uploader and coldfusion?
我正在使用 Jodit 创建一个所见即所得的编辑器。我有一个空的 coldfusion 文件 (uploadimage2.cfm)。当我将上传的 img 发送到那个空的 coldfusion 页面时,我收到一条错误消息,指出 coldfusion 找不到变量 "FILES".
Jodit 正在向 uploadimage2.cfm 发送以下表单数据:
------WebKitFormBoundaryIrkl9oNQedwACmBe
Content-Disposition: form-data; name="path"
------WebKitFormBoundaryIrkl9oNQedwACmBe
Content-Disposition: form-data; name="source"
default
------WebKitFormBoundaryIrkl9oNQedwACmBe
Content-Disposition: form-data; name="files[0]"; filename="HandShake.JPG"
Content-Type: image/jpeg
------WebKitFormBoundaryIrkl9oNQedwACmBe--
coldfusion 似乎卡在了 name="files[0]" 部分。我有一个不使用 Jodit 的工作上传功能,它发送 name="image" 代替它。
Jodit 发送时,我无法拦截表单数据以尝试重命名。
这是我的 javascript 和 Jodit 插件:
var editor = new Jodit('#newEditor',
uploader: {
url: "uploadimage2.cfm",
filesVariableName: "image"
}
);
如何为 coldfusion 发送正确的表单数据而不引发错误?
最终我发现我的问题出在我的 application.cfc
文件中。 onRequest
函数试图评估 "files[0]"
以确保其中没有脚本注入。这用于其他表单文本上传。
以下是我如何将 Jodit 上传的内容完整地与 coldfusion 一起使用:
我的 uploadimage2.cfm 文件:
<!--- set content type to json so jodit can read the response --->
<cfheader name="Content-Type" value="application/json">
<!--- create a structure with necessary objects --->
<cfset responseStruct = structNew()>
<cfset responseStruct["message"] = "File was uploaded">
<cfset responseStruct["error"] = 0>
<cfset responseStruct["path"] = "#application.image_root#">
<cfset responseStruct["images"] = []>
<cfset variables.mediapath="#application.image_upload_root#\">
<!--- loop over the form data to upload each image individually --->
<cfloop collection="#form#" item="i">
<cfif findNoCase("files",i) gte 1>
<cffile action="upload"
fileField="#i#"
destination="#variables.mediapath#"
accept="image/jpg, image/jpeg, image/png, image/gif, image/svg+xml"
nameconflict="makeunique"
result="this_image">
<cfscript>arrayAppend(responseStruct["images"],"#this_image.serverFile#");</cfscript>
</cfif>
</cfloop>
<!--- serialize the structure to json --->
<cfoutput>#serializeJSON(responseStruct)#</cfoutput>
然后在我的 Jodit 初始化中:
var editor = new Jodit('#editor',
{
uploader: {
url: "uploadimage2.cfm",
isSuccess: function (resp) {
//this step is necessary for whatever reason, otherwise it will throw an error.
return resp;
},
process: function(resp){
//this was an important step to align the json with what jodit expects.
return {
files: resp.images,
path: resp.path,
baseurl: resp.path,
error: resp.error,
message: resp.message
}
}
}
}
);
我正在使用 Jodit 创建一个所见即所得的编辑器。我有一个空的 coldfusion 文件 (uploadimage2.cfm)。当我将上传的 img 发送到那个空的 coldfusion 页面时,我收到一条错误消息,指出 coldfusion 找不到变量 "FILES".
Jodit 正在向 uploadimage2.cfm 发送以下表单数据:
------WebKitFormBoundaryIrkl9oNQedwACmBe
Content-Disposition: form-data; name="path"
------WebKitFormBoundaryIrkl9oNQedwACmBe
Content-Disposition: form-data; name="source"
default
------WebKitFormBoundaryIrkl9oNQedwACmBe
Content-Disposition: form-data; name="files[0]"; filename="HandShake.JPG"
Content-Type: image/jpeg
------WebKitFormBoundaryIrkl9oNQedwACmBe--
coldfusion 似乎卡在了 name="files[0]" 部分。我有一个不使用 Jodit 的工作上传功能,它发送 name="image" 代替它。
Jodit 发送时,我无法拦截表单数据以尝试重命名。
这是我的 javascript 和 Jodit 插件:
var editor = new Jodit('#newEditor',
uploader: {
url: "uploadimage2.cfm",
filesVariableName: "image"
}
);
如何为 coldfusion 发送正确的表单数据而不引发错误?
最终我发现我的问题出在我的 application.cfc
文件中。 onRequest
函数试图评估 "files[0]"
以确保其中没有脚本注入。这用于其他表单文本上传。
以下是我如何将 Jodit 上传的内容完整地与 coldfusion 一起使用:
我的 uploadimage2.cfm 文件:
<!--- set content type to json so jodit can read the response --->
<cfheader name="Content-Type" value="application/json">
<!--- create a structure with necessary objects --->
<cfset responseStruct = structNew()>
<cfset responseStruct["message"] = "File was uploaded">
<cfset responseStruct["error"] = 0>
<cfset responseStruct["path"] = "#application.image_root#">
<cfset responseStruct["images"] = []>
<cfset variables.mediapath="#application.image_upload_root#\">
<!--- loop over the form data to upload each image individually --->
<cfloop collection="#form#" item="i">
<cfif findNoCase("files",i) gte 1>
<cffile action="upload"
fileField="#i#"
destination="#variables.mediapath#"
accept="image/jpg, image/jpeg, image/png, image/gif, image/svg+xml"
nameconflict="makeunique"
result="this_image">
<cfscript>arrayAppend(responseStruct["images"],"#this_image.serverFile#");</cfscript>
</cfif>
</cfloop>
<!--- serialize the structure to json --->
<cfoutput>#serializeJSON(responseStruct)#</cfoutput>
然后在我的 Jodit 初始化中:
var editor = new Jodit('#editor',
{
uploader: {
url: "uploadimage2.cfm",
isSuccess: function (resp) {
//this step is necessary for whatever reason, otherwise it will throw an error.
return resp;
},
process: function(resp){
//this was an important step to align the json with what jodit expects.
return {
files: resp.images,
path: resp.path,
baseurl: resp.path,
error: resp.error,
message: resp.message
}
}
}
}
);