2011-05-19 99 views
0

我找不出如何做附件。已安裝的插件「郵件」和有問題的文件是一個.csv從窗體上傳(成功)。Grails郵件插件:attach org.springframework.web.multipart.commons.CommonsMultipartFile

這工作:

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, [email protected]3e2d16b] 
Possible solutions: each(groovy.lang.Closure) 

回答

2

如果您使用版本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

+0

f.getBytes()就是我現在所擁有的。謝謝!! – Mikey 2011-05-19 10:28:22