java - java.nio.file.InvalidPathException: Illegal char <:> at index 4: http:\182.18.177.27:78\PrepaidEMFiles\invoice12.pdf
问题描述
在发送带有附件的电子邮件时,我收到了错误。它适用于本地系统文件位置(例如 C://PrepaidEMFiles//invoice123.pdf),但是当我使用(http://182.18.177.27:78/PrepaidEMFiles/invoice1547033786877.pdf)位置时,我得到了error.below 是我的代码。
try{
`enter code here`....
String samplePdf =
"http://182.18.177.27:78/PrepaidEMFiles/invoice1547033786877.pdf";
FileSystemResource file = new FileSystemResource(samplePdf);
helper.addAttachment(file.getFilename(), file);
} catch (MessagingException e) {
LOGGER.error("Exception in sending mail", e);
exceptionHandlerDao.exceptionHandlineCode(e, "SENDING EMAIL FOR " +
inventoryName + " FOR RECHARGE A DEVICE", "");
}
sender.send(message);
}
我尝试过各种方式来忽略“\”之类的(
eg.http:\\\\182.18.177.27:78\\PrepaidEMFiles\\invoice1547033786877.pdf) but still getting the same error.Could someone please help me with that error.
提前致谢!!
我尝试了各种方法来获取带有 URL url = inputstream 示例的文件。但我将二进制文件作为附件。仍然没有用。
完全错误:java.nio.file.InvalidPathException: Illegal char <:> at index 4:
http:\182.18.177.27:78\PrepaidEMFiles\invoice1547033786877.pdf
at
sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.io.File.toPath(File.java:2234)
at org.springframework.core.io.FileSystemResource.<init>
(FileSystemResource.java:82)
at
我需要远程定位的 pdf 文件将其发送到电子邮件附件。
解决方案
问题是您正在使用 FileSystemResource 而这不在文件系统上。它是一个外部托管的 URL。您可能应该使用 URLResource 而不是 FileResource。
在这里查看更多文档
URLResource 应该能够理解您拥有的 HTTP URL。
推荐阅读
- mysql - 在不使用存储过程的情况下处理事务错误
- python - 如何删除禁止错误?
- css - 如何避免 Sass 变量名在 _variables.scss 中重复?
- python - 将 Pelican 网站部署到 Heroku 时,Markdown Math 无法正确显示
- python - 如何避免python中的并行类层次结构
- python - Python 和使用来自 Google 表格的数据
- amazon-elastic-beanstalk - AWS CDK:为 ApiGateway VPC 链接获取 ElasticBeanstalk 环境的 LoadBalancer ARN
- python - 有没有人有如何将 mplfinance 烛台图绘制到 tkinter gui 的示例?
- security - 如何启用 cookie 和安全性?
- ansible - 有条件地包含 ansible 角色的变量文件