简体   繁体   English

FileSystemResource:java.io.FileNotFoundException

[英]FileSystemResource: java.io.FileNotFoundException

I'm trying to create a fil as follows from a URL (my DropBox account), then add it as an attachment to a MimeMessageHelper, but I get a FileNotFoundException . 我正在尝试从URL(我的DropBox帐户)创建一个fil,然后将其作为附件添加到MimeMessageHelper,但出现FileNotFoundException What could I be doing wrong? 我可能做错了什么?

String[] attachments = {"https://dl.dropboxusercontent.com/s/XXXX/my%20Letter.docx"};

for (String attachment : attachments) {
    FileSystemResource file = new FileSystemResource("url:" + attachment);
    message.addAttachment(file.getFilename(), file);
}

Error: 错误:

Caused by: org.springframework.mail.MailSendException: Failed messages: javax.mail.MessagingException: IOException while sending message;
  nested exception is:
    java.io.FileNotFoundException: url:https:\dl.dropboxusercontent.com\s\XXXX\my%20Letter.docx (The filename, directory name, or volume label syntax is incorrect); message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: IOException while sending message;
  nested exception is:
    java.io.FileNotFoundException: url:https:\dl.dropboxusercontent.com\s\XXXX\my%20Letter.docx (The filename, directory name, or volume label syntax is incorrect)

UPDATE: 更新:

How can I go about creating a FileSystemResource from a Http URL? 如何从Http URL创建FileSystemResource

You can use UrlResource instead of File system resource or download the file using some http client and then attach it to email. 您可以使用UrlResource代替文件系统资源,也可以使用某些http客户端下载文件,然后将其附加到电子邮件中。

For example: 例如:

URL website = new URL("http://someurl");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("some temporary name");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

And then attach it using FileSystemResource 然后使用FileSystemResource附加它

You can use http client for this, for example: okhttp 您可以为此使用http客户端,例如: okhttp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM