Created
February 10, 2009 10:36
-
-
Save masanobuimai/61344 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
------ view.gsp ------ | |
<g:form action="save" method="post" enctype="multipart/form-data"> | |
<input type="file" id="fileStore.content" name="fileStore.content"/> | |
</g:form> | |
------ Controller.groovy ------ | |
def save = { | |
def f = request.getFile('fileStore.content') | |
if (!f.empty) { | |
def fileContent = new FileContent() | |
fileContent.image = f.bytes | |
def fileStore = new FileStore(content:fileContent) | |
fileStore.contentType = f.contentType | |
fileStore.filename = f.originalFilename | |
fileStore.save() | |
println fileStore.dump() | |
} | |
} | |
------- | |
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] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment