สร้างตัวจัดการไฟล์ง่าย ๆ ด้วยเกรลส์

Posted November 29, 2008 at Grails66
ตัวอย่างนี้ใช้ controller ตัวเดียวกับ view เป็น .gsp อีกไฟล์สร้างตัวจัดการไฟล์อย่างง่ายที่ upload, ดูและลบไฟล์ได้ มีคำอธิบายและตัวอย่าง application ที่พร้อมรันไว้บนหน้าเวบแล้วครับ

แนะนำการ Download File จากคุณสงกรานต์

Posted May 11, 2009 at Grails66
อ้างอิงจาก Thai-grails-user :: ดาวน์โหลดไฟล์ใน Grails ทำไมยากจัง ?? โดยคุณสงกรานต์ เห็นว่าน่าสนใจเลยเอามาฝากครับ วิธีการ Download File ด้วย Grails ซึ่งจะทำงานใน controller class สามารถทำได้ดังนี้ class DownloadController { def download = { String imagePath = "D:\\IMG_8684.JPG" def file = new File( imagePath ) response.setContentType("application/octet-stream") response.setHeader("Content-Disposition", "attachment;filename=${file.getName()}") response.outputStream << file.newInputStream() } } เท่านี้ก็สามารถทำได้แล้วครับ