简体   繁体   English

使用 PDFBox 保存方法将文件上传到 SFTP 服务器而不将文件存储到本地系统?

[英]Upload a file to an SFTP server using PDFBox save method without storing the file to the local system?

I'm trying to save the edited PDF which I fetched from the remote server back to its location without having it downloaded/stored on the local machine.我正在尝试将已编辑的 PDF 保存到其位置,而无需将其下载/存储在本地计算机上。 I'm using JSch SFTP method to get the input PDF file from the SFTP server using我正在使用 JSch SFTP 方法从 SFTP 服务器获取输入 PDF 文件,使用

x = new BufferedInputStream(channelSftp.get("example.pdf"));
PDDocument document = PDDocument.load(x);

and after doing some edits using PDFbox, I'm trying to save it using:在使用 PDFbox 进行一些编辑后,我尝试使用以下方法保存它:

documents.save(new File("ftp/path/location"));

I am not able to because I know it only works for your local directory only.我不能,因为我知道它只适用于您的本地目录。 Also I can see that document.save accept OutputStream` parameter, but I do not know how to use it here.我也可以看到document.save接受 OutputStream` 参数,但我不知道如何在这里使用它。

I don't have any problems with taking input using stream reader.使用 stream 阅读器进行输入没有任何问题。 All I need is to save that edited PDF back to its location (possibly replace) without having to download it on my local system.我所需要的只是将已编辑的 PDF 保存回其位置(可能替换),而无需在我的本地系统上下载它。

Use the ChannelSftp.put overload that returns OutputStream :使用返回OutputStreamChannelSftp.put重载

try (OutputStream out = channelSftp.put("example.pdf")) {
    documents.save(out);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM