从数据库发送任何类型的 javaMail 附件

发布于 2024-12-27 09:53:55 字数 536 浏览 2 评论 0原文

我有一个域类,其属性代表在我的 GSP 上上传的文件。我已将该文件定义为字节数组(byte [] 文件)。当发生某些特定操作时,我会发送带有附件的邮件。这是我的 SendMail 服务的一部分:

int i = 1;
        [requestInstance.picture1, requestInstance.picture2, requestInstance.picture3].each(){
            if(it.length != 0){
                DataSource image = new ByteArrayDataSource(it, "image/jpeg");
                helper.addAttachment("image" + i + ".jpg", image);  
                i++;
            }
         }

这适用于图像文件。但现在我希望能够处理所有文件类型,并且我想知道如何实现这一点。另外,我想在数据库中保存真实的文件名。欢迎所有帮助。

I'm have domain class with property that represents files uploaded on my GSP. I've defined that file as byte array (byte [] file). When some specific action happens I'm sending mail with attachments from. This is part of my SendMail service:

int i = 1;
        [requestInstance.picture1, requestInstance.picture2, requestInstance.picture3].each(){
            if(it.length != 0){
                DataSource image = new ByteArrayDataSource(it, "image/jpeg");
                helper.addAttachment("image" + i + ".jpg", image);  
                i++;
            }
         }

This works fine with image files. But now I want to be able to work with all file types and I'm wondering how to implement this. Also, I want to save real file name in database. All help is welcomed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2025-01-03 09:53:55

您可以看到代码中指定文件名和 MIME 类型的位置。从数据库中保存和恢复该信息以及附件数据应该很简单。

如果您试图从数据的字节数组中找出 MIME 类型是什么以及什么是好的文件名,那么这是一个更难的问题。尝试这个

You can see where the file name and MIME type are specified in your code. It should be straightforward to save and restore that information from your database along with the attachment data.

If you're trying to figure out from the byte array of data what the MIME type is and what a good filename would be, that's a harder problem. Try this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文