我正在使用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发送表单数据时,我无法截取表单数据以尝试重命名它。
下面是我的带有jodit插件的javascript:
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
                    }
                }
            }
        }
    );

10-05 21:46