如何使用Jodit上传器和Coldfusion上传图像? [英] How to upload image with Jodit uploader and coldfusion?

查看:120
本文介绍了如何使用Jodit上传器和Coldfusion上传图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jodit 创建一个所见即所得的编辑器。我有一个Coldfusion文件(uploadimage2.cfm)为空。当我将上传的img发送到该空的Coldfusion页面时,我收到一个错误,表明Coldfusion无法找到变量 FILES。

I'm using Jodit to create a wysiwyg editor. I have a coldfusion file (uploadimage2.cfm) that is empty. When I send the uploaded img to that empty coldfusion page I get an error that coldfusion can't find the variable "FILES".

Jodit将以下表单数据发送至uploadimage2.cfm:

Jodit is sending the following form data to 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代替它。

It seems coldfusion is getting stuck on the name="files[0]" part. I have a working upload function that doesn't use Jodit and it sends name="image" in place of it.

我无法拦截表单数据尝试在Jodit发送邮件时重命名。

I have not been able to intercept the form data to try to rename it when Jodit sends it.

这是我的带有Jodit插件的JavaScript:

Here's my javascript with the Jodit plugin:

var editor = new Jodit('#newEditor',
   uploader: {
        url: "uploadimage2.cfm",
        filesVariableName: "image"
   }
);

如何发送正确的表单数据进行Coldfusion而不抛出错误?

How can I send the correct form data for coldfusion to not throw errors?

推荐答案

最终,我发现我的问题出在我的 application.cfc 文件中。 onRequest 函数试图评估 files [0] ,以确保没有脚本注入它。

Eventually I figured out that my problem was in my application.cfc file. The onRequest function was trying to evaluate "files[0]" in order to make sure there was no script injection in it. This was used for other form text uploads.

这是我如何让Jodit上载完全与Coldfusion一起使用的方式。

Here's how I got the Jodit upload to work with coldfusion in it's entirety:

我的uploadimage2.cfm文件:

My uploadimage2.cfm file:

<!--- 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初始化中:

Then in my Jodit initialization:

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上传图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆