【问题标题】:Upload a file to an SFTP server using PDFBox save method without storing the file to the local system?使用 PDFBox 保存方法将文件上传到 SFTP 服务器而不将文件存储到本地系统?
【发布时间】:2021-05-06 15:15:55
【问题描述】:

我正在尝试将从远程服务器获取的已编辑 PDF 保存回其位置,而无需将其下载/存储在本地计算机上。我正在使用 JSch SFTP 方法从 SFTP 服务器获取输入 PDF 文件,使用

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

在使用 PDFbox 进行一些编辑后,我正在尝试使用以下方法保存它:

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

我不能,因为我知道它仅适用于您的本地目录。另外我可以看到document.save接受OutputStream`参数,但我不知道如何在这里使用它。

使用流阅读器获取输入没有任何问题。 我所需要的只是将编辑后的 ​​PDF 保存回其位置(可能替换),而无需在我的本地系统上下载它。

【问题讨论】:

    标签: java sftp pdfbox jsch


    【解决方案1】:

    使用ChannelSftp.put overload that returns OutputStream:

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

    【讨论】:

      猜你喜欢
      • 2021-10-14
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      • 2018-06-30
      • 2014-09-08
      • 1970-01-01
      • 2016-01-28
      相关资源
      最近更新 更多