Hi,
here i will explain how to download a static file in grails. for this, create documents folder in your web-apps. place your static file in documents. then place given code in your controller.
def excelDownload(){
def fileName = 'StockUpload.xls'
downloadFile(fileName,
servletContext.getRealPath(File.separator+"documents"+File.separator+fileName))
redirect action:'upload'
}
def downloadFile(fileName,path) {
def file = new File(path)
if (file.exists()) {
response.setContentType("application/download")
response.setHeader('Content-Disposition', "Filename="+fileName)
response.outputStream << file.bytes
}
return
}
here i will explain how to download a static file in grails. for this, create documents folder in your web-apps. place your static file in documents. then place given code in your controller.
def excelDownload(){
def fileName = 'StockUpload.xls'
downloadFile(fileName,
servletContext.getRealPath(File.separator+"documents"+File.separator+fileName))
redirect action:'upload'
}
def downloadFile(fileName,path) {
def file = new File(path)
if (file.exists()) {
response.setContentType("application/download")
response.setHeader('Content-Disposition', "Filename="+fileName)
response.outputStream << file.bytes
}
return
}
No comments:
Post a Comment