gpt4 book ai didi

java - FileSystemResource : java. io.FileNotFoundException

转载 作者:行者123 更新时间:2023-12-01 11:11:07 32 4
gpt4 key购买 nike

我尝试从 URL(我的 DropBox 帐户)创建如下所示的 fil,然后将其作为附件添加到 MimeMessageHelper,但我收到 FileNotFoundException。我可能做错了什么?

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);
}

错误:

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)
<小时/>

更新:

如何从 Http URL 创建 FileSystemResource

最佳答案

您可以使用 UrlResource 代替文件系统资源,或者使用某些 http 客户端下载文件,然后将其附加到电子邮件中。

例如:

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);

然后使用FileSystemResource附加它

您可以使用 http 客户端来实现此目的,例如:okhttp

关于java - FileSystemResource : java. io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32362022/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com