Grails 邮件插件:附加 org.springframework.web.multipart.commons.CommonsMultipartFile

发布于 2024-11-08 05:00:20 字数 1222 浏览 2 评论 0原文

我不知道如何做附件。已安装插件“mail”,并且相关文件是从表单(成功)上传的 .csv。

这有效:

def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  to "[email protected]"
  subject "subject"
  body bodyString
}

这不起作用:

def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  multipart true
  to "[email protected]"
  subject "subject"
  body bodyString
  attach "myfile.csv", f
}

哦,是的,错误是这样的:

groovy.lang.MissingMethodException: No signature of method: my_project.MySweetController.attach() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.springframework.web.multipart.commons.CommonsMultipartFile) values: [Demo myfile.csv, org.springframework.web.multipart.commons.CommonsMultipartFile@73e2d16b]
Possible solutions: each(groovy.lang.Closure)

I cannot figure out how to do attachments. Installed plugin "mail" and the file in question is a .csv being uploaded (successfully) from a form.

This works:

def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  to "[email protected]"
  subject "subject"
  body bodyString
}

This doesn't:

def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  multipart true
  to "[email protected]"
  subject "subject"
  body bodyString
  attach "myfile.csv", f
}

Oh yeah the error says this:

groovy.lang.MissingMethodException: No signature of method: my_project.MySweetController.attach() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.springframework.web.multipart.commons.CommonsMultipartFile) values: [Demo myfile.csv, org.springframework.web.multipart.commons.CommonsMultipartFile@73e2d16b]
Possible solutions: each(groovy.lang.Closure)

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

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

发布评论

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

评论(1

听闻余生 2024-11-15 05:00:20

如果您使用的是 0.9 或更高版本的邮件插件,则以下内容应该可以

def f = request.getFile('uploadedFile')

//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  multipart true
  to "[email protected]"
  subject "subject"
  body bodyString
  attachBytes "Some-File-Name.csv", "text/csv", f.bytes
}

正常工作,您对邮件服务 MailService 的引用名称很特殊。如果您通过自动装配 Spring bean 来获取对此服务的引用,我希望它是 mailService

If you're using version 0.9 or later of the mail plugin, the following should work

def f = request.getFile('uploadedFile')

//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  multipart true
  to "[email protected]"
  subject "subject"
  body bodyString
  attachBytes "Some-File-Name.csv", "text/csv", f.bytes
}

incidentally, the name of your reference to the mail service MailService is peculiar. If you're getting a reference to this service by autowiring the Spring bean, I would expect it to be mailService

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