Created
February 10, 2009 06:17
-
-
Save masanobuimai/61269 to your computer and use it in GitHub Desktop.
Grailsでファイルのダウンロード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileStore { | |
String filename | |
FileContent content | |
String contentType | |
public String toString() { "$id:$filename" } | |
static mapping = { | |
content lazy: true | |
} | |
} | |
------ | |
class FileContent { | |
byte[] image | |
static def belongsTo = [fileStore: FileStore] | |
} | |
------ | |
import javax.mail.internet.MimeUtility | |
class FileStoreController { | |
def show = { | |
def fileStore = FileStore.get(params.id) | |
if (request.getHeader('User-Agent') =~ /^MSIE/) { | |
response.setHeader('Content-disposition', | |
"attachment; filename=${MimeUtility.encodeWord(fileStore.filename, 'ISO-2022-JP', 'B')}") | |
} else { | |
response.setHeader('Content-disposition', | |
"attachment; filename=${URLEncoder.encode(fileStore.filename, 'UTF-8')}") | |
} | |
response.contentType = fileStore.contentType | |
response.outputStream << fileStore.content.image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment