How to convert InputStream to inputstreamsource or datasource to attach in spring JavaMail

I'm getting the input stream from jsch channelsftp, as shown 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 unixpath in the spring JavaMail attachment But when I see the API of the spring JavaMail addattachment () method, it only needs inputstreamsource or datasource My problem is that I can't get inputstreamsource or datasource from InputStream. I get it from SFTP channel How do I get inputstreamsource or datasource from the input stream above? Thank you in advance

Solution

From the document, inputstreamsource is an interface One implementation is inputstreamresource, which has a constructor to receive InputStream Here is the JavaDoc for it.

You should be able to set up your phone like this:

addAttachment("Not porn",new InputStreamResource(inputStream));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>