gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 15:14:28 32 4
gpt4 key购买 nike

我不知道该怎么做附件。已安装插件“邮件”,相关文件是从表单上载(成功)的.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的引用名称很特殊。如果您通过 Autowiring Spring bean获得对该服务的引用,我希望它是 mailService

关于spring - Grails邮件插件:附加org.springframework.web.multipart.commons.CommonsMultipartFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6053781/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com