на класс домена:Как обновить изображение при редактировании вида grails?
class Employee {
String name
...
...
byte[] picture
static constraints = {
name()
.....
picture (nullable:true, maxSize: 1048576 /* 16K */)
}
}
на представлении формы:
<div id="preview" class="thumbnail">
<a href="#" id="file-select" class="btn btn-default">Choose File</a>
<img class="img-circle" alt="User Image" style="width:100%;"
src="${employeeInstance?.picture?
createLink(controller:'employee', action:'image',
id:employeeInstance.id):assetPath(src: 'user-default.png')}"/>
</div>
<input type="file" id="picture" name="picture" class="form-control" />
<span class="alert alert-info" id="file-info">No file yet</span>
на контроллере:
def image() {
def avatarUser = Employee.get(params.id)
if (!avatarUser || !avatarUser.picture){//|| !avatarUser.avatarType) {
response.sendError(404)
return
}
response.contentType = "image/jpeg"//avatarUser.avatarType
response.contentLength = avatarUser.picture.size()
OutputStream out = response.outputStream
out.write(avatarUser.picture)
out.close()
}
protected void notFound() {
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'employee.label', default: 'Employee'), params.id])
redirect action: "index", method: "GET"
}
}
}
Я загрузить изображение и представить его на редактирование зрения, но во время обновления не сохраняет изображение, даже если я не меняю изображение.
Как выглядит ваш метод обновления? – Gregg