简体   繁体   English

通过Ajax将base64图像数据发送到cfc

[英]send base64 image data to cfc via ajax

I am using html2canvas.js to create a <canvas> image from a div on a page. 我正在使用html2canvas.js从页面上的div创建<canvas>图像。 What I'd like to do is send the rendered base64 image to a cfc via ajax so I can actually save the image to a folder on the server and return the file path to the page. 我想做的是通过ajax将渲染的base64图像发送到cfc,这样我实际上可以将图像保存到服务器上的文件夹中,并将文件路径返回到页面。

The issue I am running into is that when I send the base64 encoded data to the cfc, the cfc interprets the data, but with several instances of "[invalid]" within the data. 我遇到的问题是,当我将base64编码的数据发送到cfc时,cfc会解释该数据,但在数据中包含“ [invalid]”的多个实例。

If I just post the image to the DOM, the image renders just fine. 如果我只是将图像发布到DOM,则图像呈现就很好。 Here is a link to a gist that has both the normal image created compared to the one that I dump from the argument passed into the cfc: https://gist.github.com/ronnieduke/d83dfb3e31677191f88e 这是一个要点的链接,该要点具有创建的普通图像与我从传递给cfc的参数中转储的图像相比所创建的图像: https : //gist.github.com/ronnieduke/d83dfb3e31677191f88e

Here is the Ajax I am running (where img.src is the result of the canvas data posted in the link above) 这是我正在运行的Ajax(其中img.src是上面链接中发布的canvas数据的结果)

 var image = new Image(); image.id = 'pic'; // This results in the base64 data posted in image-normal.txt in the gist image.src = canvas.toDataURL("image/png"); var data = new FormData(); data.append('imgData',image.src); // Genrate images in cfc $.ajax({ url: 'my.cfc?method=generateImage', type:'POST', data:data, dataType:'JSON', processData: false, cache:false, async:false, contentType: false, success:function(data){ console.log(data); }, error:function(result){ alert(result.responseText); } }); 

And here is my cfc: 这是我的cfc:

<cffunction name="generateImage" output="true" access="remote" returnFormat="JSON">
<cfargument name="imgData" required="true" type="string">

<cfset request.acceptExt = 'image/jpg,image/gif,image/png' />

<cfset image = imageReadBase64(arguments.imageData)>

<cfimage
    action="write"
    destination="image.png"
    source="#image#"
    overwrite="yes"
>

What's happening is that the imageReadBase64() function is throwing an error that it can't read the PNG data. 发生的情况是imageReadBase64()函数抛出一个错误,它无法读取PNG数据。 When I dump arguments.imgData that's when I get the result posted in the img-cfc.txt in the gist above. 当我转储arguments.imgData ,就是在上面要点中将结果发布在img-cfc.txt中的时候。 That is what contains all the [INVALID] instances. 那就是包含所有[INVALID]实例的内容。

What I found interesting is that when comparing the two versions of the base64 image closely, I noticed that wherever it has [INVALID] from the cfc version, the letters "QSS" (in various cases) appear in the normal version. 我发现有趣的是,当比较base64映像的两个版本时,我注意到无论cfc版本中具有[INVALID]的位置,字母“ QSS”(在各种情况下)都会出现在普通版本中。

For example: 例如:

Normal: ...6s9QSSpN... 正常: ...6s9QSSpN...

Dumped from cfc argument: ...6s9[INVALID]pN... 从cfc参数中转储: ...6s9[INVALID]pN...


Normal: ...CwKGgwqsSH7Qyq1g... 正常: ...CwKGgwqsSH7Qyq1g...

Dumped from cfc argument: ...CwKGgw[INVALID]H7Qyq1g... 从cfc参数转储: ...CwKGgw[INVALID]H7Qyq1g...

I would expect something like that from special characters or something, but I'm not sure what "QSS" has to do with anything. 我期望特殊字符之类的东西,但是我不确定“ QSS”与什么有关。

I have tried all kinds of different encoding/decoding on both the JS side and the CFC side, and nothing is working. 我已经在JS端和CFC端尝试了各种不同的编码/解码,但是没有任何效果。 Any thoughts or insight would be greatly appreciated! 任何想法或见识将不胜感激!

Thanks in advance, 提前致谢,

UPDATE: The issue was in fact with the 'QSS' being a variable in Mura for XSS. 更新:问题实际上是“ QSS”是Mura for XSS中的变量。 Once I added the field name in my settings.ini as an exception, the data came across normally. 一旦将字段名称添加到settings.ini中作为例外,数据就可以正常显示了。

The issue was in fact with the 'QSS' being a variable in Mura for XSS. 实际上,问题在于“ QSS”是Xura的Mura中的变量。 Once I added the field name in my settings.ini as an exception, the data came across normally. 一旦将字段名称添加到settings.ini中作为例外,数据就可以正常显示了。

Update from J. Dean Example settings.ini.cfm line: 从J. Dean示例settings.ini.cfm行更新:

scriptprotectexceptions=eventid,body

This will tell Mura to ignore these fields when doing its XSS blacklisting. 这将告诉Mura在进行XSS黑名单时忽略这些字段。 In my case, the eventid field had really long string of characters that happened to have QSS in it, causing me HUGE intermittent headaches. 就我而言,eventid字段中的字符串确实很长,恰好包含QSS,这使我感到间歇性的头痛。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM