Pdf 为什么会出现未知错误?
这是我的错误消息: ColdFusion无法删除该文件 C:\path\guid.png 不知什么原因 我已经检查过了,以确保我的coldFusion用户有权按照建议这样做。这不是问题所在,用户拥有所有权限。不幸的是,代码在生产服务器上被破坏,而不是我自己的本地服务器(可能是相关的)。生产在CF11上,但我在CF9上 代码如下:Pdf 为什么会出现未知错误?,pdf,coldfusion,server,Pdf,Coldfusion,Server,这是我的错误消息: ColdFusion无法删除该文件 C:\path\guid.png 不知什么原因 我已经检查过了,以确保我的coldFusion用户有权按照建议这样做。这不是问题所在,用户拥有所有权限。不幸的是,代码在生产服务器上被破坏,而不是我自己的本地服务器(可能是相关的)。生产在CF11上,但我在CF9上 代码如下: <cffunction name="svgToPDF" access="public" output="false" returntype="string">
<cffunction name="svgToPDF" access="public" output="false" returntype="string">
<cfargument name="svg" required="true" type="string" />
<cfset var local = {} />
<cfset local.guid = CreateUUID() />
<cfset local.outPDF = ExpandPath(local.guid & '.pdf') />
<cfset local.svg = DeserializeJSON(exportToImage(svg=arguments.svg)) />
<cfif local.svg.error>
<!-- Conversion error -->
<cfset FileDelete(#local.svg.file#) />
<cfreturn '' />
</cfif>
<!--- rotate the png --->
<cfimage
action="read"
source="#local.svg.file#"
name="local.objImage" />
<cfimage
action="rotate"
source="#local.objImage#"
angle="90"
name="local.objImage" />
<cfimage
action="write"
source="#local.objImage#"
destination="#local.svg.file#"
overwrite="yes" />
<!--- Add the png to the pdf, write the pdf file, and delete the png --->
<cfscript>
img = CreateObject("java", "com.lowagie.text.Image");
png = img.getInstance(local.svg.file);
document = CreateObject("java", "com.lowagie.text.Document");
document.init(png);
fileIO = CreateObject("java", "java.io.FileOutputStream");
fileIO.init(local.outPDF);
writer = CreateObject("java", "com.lowagie.text.pdf.PdfWriter");
writer.getInstance(document, fileIO);
document.setMargins(0, 0, 0, 0);
document.open();
document.add(png);
document.close();
FileDelete(#local.svg.file#); <!--- This is the line where it breaks--->
</cfscript>
<cfreturn local.outPDF />
</cffunction>
img=CreateObject(“java”、“com.lowagie.text.Image”);
png=img.getInstance(local.svg.file);
document=CreateObject(“java”、“com.lowagie.text.document”);
文件.init(png);
fileIO=CreateObject(“java”、“java.io.FileOutputStream”);
fileIO.init(local.outPDF);
writer=CreateObject(“java”,“com.lowagie.text.pdf.PdfWriter”);
writer.getInstance(文档、文件IO);
document.setMargins(0,0,0,0);
document.open();
文件。添加(png);
document.close();
FileDelete(#local.svg.file#);
如何修复此函数?
谢谢如果您的生产服务器是CF11,那么这是一个在bug#4031026- 该漏洞已经由Adobe验证,修复将到期,最有可能在他们的下一个热修复中
JPEG似乎是目前唯一一种没有锁定问题的格式。我知道这不是错误,但您在示例中打断的行上的注释对cfscript无效。应该以
/
开头,或者用/***/
包装,如果在删除之前转储/记录文件exists(local.svg.file)
会发生什么?你能看到文件是否真的在服务器上写入吗?如果你在Windows上,很可能是文件系统锁定了文件。同意,听起来确实有东西锁定了文件。A) 错误堆栈跟踪是否包含更多详细信息?B) 在prod中是否每次都会发生这种情况?C) 对于GRIN,如果您临时使用字节数组(即bytes=fileReadBinary(local.svg.file))的任何更改;getInstance(javacast(“byte[]”,bytes))
而不是从这里的文件加载img.getInstance(local.svg.file)
?如果这是CF 10/11,那么这就是这里提到的一个bug-