I want to create a Java File
object in memory (without creating a physical file) and populate its content with a byte array.
Can this be done?
The idea is to pass it to a Spring InputStreamSource
. I'm trying the method below, but it returns saying "the byte array does not contain a file name.".
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setFrom("[email protected]", "xyz");
helper.setTo(email);
helper.setText(body,true);
helper.setSubject(subject);
helper.addInline("cImage",
new InputStreamResource(new ByteArrayInputStream(imageByteArr)));
mailSender.send(message);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…