Coldfusion 拒绝解码 Base64 图像

发布于 2024-12-22 10:25:32 字数 562 浏览 2 评论 0原文

几个小时前,我发现我可以通过表单属性传递文件api创建的DataUrl,轻松地在html5文件api和coldfusion之间进行通信,并让coldfusion为我将图像文件写入服务器。

这很好用。

然而现在,它拒绝解码我传递的这些 Base64 字符串。我已经在其他解码器中测试了 Base64 字符串,它们可以正确显示图像。我没有对代码进行任何更改。那么谁能告诉我这里发生了什么事..?

<cfimage source="#attributes.image#" action="write" destination="../images/new_image.png" isBase64="yes" overwrite="true">

2012 年 20 月编辑: 今天,当我在工作中打开计算机时,它又开始工作了。我仍然不清楚昨天发生了什么。 Coldfusion 返回的错误是:“该文件似乎不是 base64 编码的”,这绝对是,我检查了不止一次。我传递给 cfimage 标记的 base64 字符串包含标头,就像您所描述的那样。

A couple of hours ago I found that I could easily communicate between the html5 file api and coldfusion by passing along the DataUrl created by the file api through form attributes and let coldfusion write the image file for me to the server.

This worked fine.

Now however, it refuses to decode these base64 strings I'm passing along. I've already tested the base64 strings in other decoders and they display the image correctly. I haven't changed anything to the code. So can anyone please tell me what's going on here..?

<cfimage source="#attributes.image#" action="write" destination="../images/new_image.png" isBase64="yes" overwrite="true">

edit 20/12:
Today it started working again when I turned on my computer at work. It is still not clear to me what happened yesterday. The error Coldfusion returned was: 'the file does not appear to be base64-encoded', which it absolutely was, I checked more than once. The base64-string I passed to the cfimage tag contained headers just like you described.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

节枝 2024-12-29 10:25:32

如果您所做的只是按原样保存,则可以跳过 标记并使用 标记。 会增加大量开销,并且仅当您计划在保存图像之前修改图像时才有用。

例如。

<cffile action="write" file="C:\temp\test-image.jpg" output="#binaryDecode(base64data)#" addnewline="no">

或者尝试...

<cfset myImage = imageReadBase64(base64data)>
<cfimage action="write" source="#myImage#" destination="C:\temp\test-image.jpg">

您的 base64 字符串有标头吗?

例如。 "data:image/jpg;base64,..." 在字符串的开头?

从内存来看,imageReadBase64() 支持带头和不带头的 Base64 字符串。

http://www.cfquickdocs.com/cf9/#BinaryDecode

http://www.cfquickdocs.com/cf9/#ImageReadBase64

You could skip the <cfimage> tag and use a <cffile> tag if all you are doing is saving it exactly as is. <cfimage> adds a bunch of overhead and is only useful if you plan to modify the image before saving it.

Eg.

<cffile action="write" file="C:\temp\test-image.jpg" output="#binaryDecode(base64data)#" addnewline="no">

Alternatively try...

<cfset myImage = imageReadBase64(base64data)>
<cfimage action="write" source="#myImage#" destination="C:\temp\test-image.jpg">

Does your base64 string have headers?

eg. "data:image/jpg;base64,..." at the start of the string?

From memory, imageReadBase64() supports base64 strings with and without headers.

http://www.cfquickdocs.com/cf9/#BinaryDecode

http://www.cfquickdocs.com/cf9/#ImageReadBase64

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文