0
데이터베이스에 저장된 이미지를 표시하려고 할 때 FF 콘솔에서 "이미지가 손상되거나 잘립니다."라는 오류가 발생합니다. 나는 Grails와 Hibernate를 사용하고있다. 단지 내 gsp 페이지에 사용자의 프로필 사진을 표시하려고합니다.GRAILS- 이미지가 손상되거나 자름
< property name="photo" type="binary" column="PHOTO" not-null="false" />
이 collumn는 DB에 BLOB입니다 :
내 도메인 클래스 사용자는 바이트로 정의 된 속성 사진 []
public class User {
private String userId;
private byte[] photo;
.
.
.
user.hbm.xml 매핑이 있습니다.
내 GSP :
< div id="user-view-thumbnail-container">
<fieldset>
<legend>Photo Upload</legend>
<g:form action="uploadPhoto" method="post" enctype="multipart/form-data">
<label for="photo">Photo</label>
<input type="file" name="photo" id="photo" />
<input type="submit" class="buttons" value="Upload" />
</g:form>
</fieldset>
<g:if test="${user.photo}">
<img alt="User Photo" src="${createLink(controller:'profile', action:'profile_image', id:user.userId)}" />
</g:if>
</div>
ProfileController :
def uploadPhoto = {
def user = userService.getUser(authenticateService.principal())
def f = request.getFile('photo')
user.setPhoto(f.getBytes())
if (!user.save()) {
//doesn´t matter now
return;
}
redirect(action: 'index', model:[user: user])
}
def profile_image = {
def user = userService.getUser(params.id)
if (!user) {
response.sendError(404)
return;
}
response.setContentType(user.photo.contentType())//'image/png', 'image/jpeg', 'image/gif'
response.setContentLength(user.photo.size())
OutputStream out = response.getOutputStream();
out.write(user.photo);
out.close();
}
참고 : 사진은 내가 그것을 볼 수 있습니다 올바르게 DB에 저장되지만 내 GSP에 보여 할수 없어.
아이디어가 있으십니까?
감사합니다. 많은 사람들,
의견에 이러한 유형의 의견을 추가하십시오. –
작동합니다. 감사합니다. – user1286733