Coldfusion文件上传一个cfDocument

问题描述 投票:1回答:1

我使用cfDocument创建一个pdf,我试图使用fileUpload将其上传到我的服务器,但它给出了错误:ByteArray objects cannot be converted to strings.

这是我的代码:

// Create PDF
formPdf = "";
cfDocument(format="PDF", name="formPdf") { writeOutput(formContent); };

// Upload the PDF
destination = expandPath("./MyFolder/#ID#/");
if(!directoryExists(destination)){
    directoryCreate(destination);
}
fileUpload( destination, formPdf, "*.", "MakeUnique" );

fileUpload()只能使用字符串吗?如何上传刚刚创建的PDF文件?

谢谢

file-upload coldfusion cfml
1个回答
4
投票

根据您的要求,无需上传文件,因为它已经在您的服务器上,并且cfdocument可以处理生成和保存PDF文件。

有关https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-d-e/cfdocument.html的更多信息,请参阅cfdocumentcfdocument旨在通过格式化输入创建PDF。

你想要filenamecfdocument属性。这将定义将包含输出的文件的路径名。

你会想要这样的东西:

destination = expandPath("./MyFolder/#ID#/");
if(!directoryExists(destination)){
    directoryCreate(destination); 
}

pdfName = "calculatedPDFName.pdf" ;

// Create PDF 
cfdocument(format="PDF", filename="#destination#/#pdfName#") {
    writeOutput( sanitizeMe(formContent) ) ;   
};

我将sanitizeMe()作为提醒,在您使用它之前清理任何表单输入或提供备份,或者在您将其保存回文件系统之前。这没有做任何事情,但应该有所作为。围绕这些互联网进行了大量关于如何以及为何这样做的讨论。

注意:我打算链接几个讨论XSS和其他注入问题的页面,弹出的第一个链接是SO。 In ColdFusion How to Eliminate Vulnerable for Cross-Site Script当我低头看答案时,我意识到这是去年的一个。发生这种情况时,一定要爱。 :-)

© www.soinside.com 2019 - 2024. All rights reserved.