Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails邮件插件:attach org.springframework.web.multipart.commons.commons multipartfile_Spring_Email_Grails_Attachment - Fatal编程技术网

Grails邮件插件:attach org.springframework.web.multipart.commons.commons multipartfile

Grails邮件插件:attach org.springframework.web.multipart.commons.commons multipartfile,spring,email,grails,attachment,Spring,Email,Grails,Attachment,我搞不懂怎么做附件。已安装插件“mail”,并且所讨论的文件是从表单上载(成功)的.csv文件 这项工作: def f = request.getFile('uploadedFile') //do a bunch of stuff with f and make bodyString MailService.sendMail { to "myemail@secretplace.com" subject "subject" body bodyString } 这并不是: def f

我搞不懂怎么做附件。已安装插件“mail”,并且所讨论的文件是从表单上载(成功)的.csv文件

这项工作:

def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  to "myemail@secretplace.com"
  subject "subject"
  body bodyString
}
这并不是:

def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  multipart true
  to "myemail@secretplace.com"
  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)

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

def f = request.getFile('uploadedFile')

//do a bunch of stuff with f and make bodyString
MailService.sendMail {
  multipart true
  to "myemail@secretplace.com"
  subject "subject"
  body bodyString
  attachBytes "Some-File-Name.csv", "text/csv", f.bytes
}
顺便说一句,您对邮件服务
MailService
的引用的名称是特殊的。如果您通过自动连接Springbean获得对该服务的引用,我希望它是
mailService

f。getBytes()就是我现在拥有的。非常感谢。