我在读取来自服务器的响应时遇到问题。如果我使用 StoreFile 参数并通过 URL 访问 PDF 看起来很棒,但是通过我自己的服务器提供它总是会使页面变为空白。可能是编码问题?
def convertPdf(document) {
File f = new File(document)
RestBuilder rest = new RestBuilder()
def resp = rest.post("https://do.convertapi.com/Word2Pdf") {
contentType "multipart/form-data"
ApiKey = "CONFIDENTIAL"
file = f
}
InputStream istream = new ByteArrayInputStream(resp.getBody().getBytes());
File file = new File("123123.pdf");
FileOutputStream ostream = new FileOutputStream(file);
byte[] b = new byte[1024];
int num = 0;
while ((num = istream.read(b)) != -1) {
ostream.write(b, 0, num);
}
istream.close();
ostream.flush();
ostream.close();
}