Issue
I am getting inputstream from the Jsch channelSFTP like below.
ChannelSftp channelSftp = (ChannelSftp) channel;
InputStream input = channelsftp.get(unixPath); // unixPath is path to my file which is on SFTP server
I have to attach the file in the unixPath
in the Spring JavaMail attachment. But when I see API of Spring JavaMail addAttachment()
method it takes only InputStreamSource
or Datasource
.
My problem is I am not able to get the InputStreamSource
or Datasource
from the inputStream which I am getting form SFTP channel.
How Can I get InputStreamSource
or Datasource
from the above InputStream
?
Solution
From the documentation, InputStreamSource
is an interface. One of its implementations is InputStreamResource
, which has a constructor that takes in an InputStream
. Here is the JavaDoc for it.
You should be able to setup your call as such:
addAttachment("Not porn", new InputStreamResource(inputStream));
Answered By - nicholas.hauschild
Answer Checked By - Marie Seifert (JavaFixing Admin)