Email File Using Grails Graphics

I am currently using the export plugin to create an excel file on the fly on the server and then send it to the browser via response.outputstream (executed by the export plugin). Instead, I want it to create an excel file and as soon as it is done send it to the user. Assuming I have a letter, can anyone show me some sample code?

I looked at the export plugin code and it looks like it is writing to the response output stream. Can I somehow read from this output stream, create a file, and not store it on disk and just send it by email?

+4
source share
2 answers

.

File exportOutput = new File("/home/mkb/test.csv")
def exportOutputStream = new FileOutputStream(exportOutput)
exportService.export('csv', exportOutputStream, User.list(), fields, labels, formatters, parameters)

, grails mail plugin .

+4

attach(String fileName, String contentType, InputStreamSource source) DSA Grails Mail. , .

import org.springframework.core.io.ByteArrayResource
...

OutputStream outputStream = new ByteArrayOutputStream()
exportService.export(type, outputStream, objects, fields, labels, formatters, parameters)
InputStreamSource inputStream = new ByteArrayResource(outputStream.bytes)  //copy output stream to input stream

sendMail {
   mutipart true
   to "someone@org.com"
   attach "yourfile.txt", "text/plain", inputStream
}

.

, !

+2

All Articles