How to convert input stream to InputStreamsource or Datasource to connect in Spring JavaMail

I get input 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 need to attach a file in unixPath in a Spring javaMail application. But when I see the Spring JavaMail API addAttachment() , it only accepts InputStreamSource or Datasource . My problem is that I cannot get an InputStreamSource or Datasource from an inputStream, which I get as an SFTP channel. How can I get an InputStreamSource or Datasource from the above input stream? Thank you in advance.

+4
source share
1 answer

From the documentation, InputStreamSource is an interface. One of its implementations is an InputStreamResource that has a constructor that accepts an InputStream . Here is the JavaDoc for it .

You can customize your call as such:

 addAttachment("Not porn", new InputStreamResource(inputStream)); 
+17
source

Source: https://habr.com/ru/post/1444174/


All Articles