我正在为Gmail邮件服务器编写一个简单的电子邮件客户端,我希望能够通过JS制作的网络界面下载附件。 我将附件下载到本地文件夹
private List<File> getAttachmentsFromMessage (Message message, int j) throws IOException, MessagingException {
List<File> attachments = new ArrayList<>();
Multipart multipart = (Multipart) message.getContent();
for (int i = 0; i < multipart.getCount() ; i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
if (Part.ATTACHMENT.equalsIgnoreCase( bodyPart.getDisposition())){
File file = new File("target\\att\\" + j +"_"+ bodyPart.getFileName());
((MimeBodyPart) bodyPart).saveFile(file);
attachments.add(file);
}
}
return attachments;
}
然后尝试通过链接将其传输到Web界面
for (let j = 0; j <links_to_attachments.length ; j++) {
attachment_holder = document.createElement('div');
let a = document.createElement('a');
a.setAttribute('href','http://localhost/javaProjects/CRM/target/att/1_att1.docx');
a.download = '1.docx';
a.appendChild(document.createTextNode('link'));
attachment_holder.appendChild(a);
}
但是这种方法没有用。 而且似乎也没有办法直接链接到附件。
您能帮我解决这个问题吗?我如何通过链接下载这些附件?