gpt4 book ai didi

grails - 在 Grails 中下载 Docusign PDF,文件损坏

转载 作者:行者123 更新时间:2023-12-02 14:43:15 24 4
gpt4 key购买 nike

使用 Groovy 1.8.6 和 Grails 2.1.0

使用嵌入式 API,在用户签署文档后,浏览器被重定向回我的应用程序。使用 "Get Envelope Documents and Certificate"用于将文档下载到服务器的 API。网址格式:
"${baseUrl}/envelopes/${envelopeId}/documents/combined"
代码片段(删除了次要细节):

private void getDocument(requestUrl) {
def connection = urlConnect(requestUrl, null, "GET")
if (connection.responseCode == 200) {
savePDF(envelopeId, connection.inputStream)
}
}
private void savePDF(envelopeId, inputStream) {
String filePath = getSavedPDFPath(envelopeId)
def pdfWriter = new File(filePath).newWriter()
pdfWriter << inputStream
pdfWriter.close()
}

发生的情况是生成的文件不是 100% 正确,Adobe Reader 提示 "at least one signature is invalid" .读者至少知道该文件是由 DocuSign, Inc. 签署的,并且可以显示有关证书的详细信息。

最佳答案

根据问题的评论线程,问题是由文件的保存方式引起的。改用此代码,文件将正确保存/打开:

private void savePDF(envelopeId, connection) 
{
FileOutputStream fop = null;
File file;
String filePath = getSavedPDFPath(envelopeId);
try {
file = new File(filePath);
fop = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int numRead;
while((numRead = connection.getInputStream().read(buffer)) > 0)
{
fop.write(buffer, 0, numRead);
}
fop.flush();
fop.close();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}

关于grails - 在 Grails 中下载 Docusign PDF,文件损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24265248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com