Grails 未在.doc文件中呈现图像
我有一个模板,其中有一些图像,一个来自文件系统,另一个来自project images文件夹 模板中来自my grails应用程序的Images文件夹的图像完美地显示在doc文件中。我正在使用以下代码渲染这些图像:Grails 未在.doc文件中呈现图像,grails,groovy,gsp,doc,grails-2.2,Grails,Groovy,Gsp,Doc,Grails 2.2,我有一个模板,其中有一些图像,一个来自文件系统,另一个来自project images文件夹 模板中来自my grails应用程序的Images文件夹的图像完美地显示在doc文件中。我正在使用以下代码渲染这些图像: <img src="${g.resource(dir: 'images', file: 'phone-1.gif', absolute: true)}"/> 但我有一个来自文件系统(/opt/profileImages文件夹)的图像。使用以下代码在模板中渲染此图像:
<img src="${g.resource(dir: 'images', file: 'phone-1.gif', absolute: true)}"/>
但我有一个来自文件系统(/opt/profileImages文件夹)的图像。使用以下代码在模板中渲染此图像:
查看:
<g:img uri="${g.createLink(controller: 'personalDetail', action: 'showUserProfileImage', absolute: true)}"/>
def showUserProfileImage() {
User user = springSecurityService.currentUser as User
String profilePicturePath = "${grailsApplication.config.profilePictureDirectoryPath}/${user?.profilePicture?.fileName}"
File file = new File(profilePicturePath)
def img = file.bytes
response.contentType = user?.profilePicture?.mimeType
response.outputStream << img
response.outputStream.flush()
}
控制器:
<g:img uri="${g.createLink(controller: 'personalDetail', action: 'showUserProfileImage', absolute: true)}"/>
def showUserProfileImage() {
User user = springSecurityService.currentUser as User
String profilePicturePath = "${grailsApplication.config.profilePictureDirectoryPath}/${user?.profilePicture?.fileName}"
File file = new File(profilePicturePath)
def img = file.bytes
response.contentType = user?.profilePicture?.mimeType
response.outputStream << img
response.outputStream.flush()
}
def showUserProfileImage(){
用户用户=springSecurityService.currentUser作为用户
String profilePicturePath=“${grailsApplication.config.profilePictureDirectory路径}/${user?.profilePicture?.fileName}”
文件文件=新文件(profilePicturePath)
def img=file.bytes
response.contentType=user?.profilePicture?.mimeType
response.outputStream这里,您正试图从应用程序上下文中访问图像src。
所以你的来源应该是这样的
<g:img uri="${profilePocturePath}" width="93px" height="100px"/>
参考此
<mvc:resources mapping="/images/**" location="file:/absolute/path/to/image/dir"/>
解决方案仅在服务器在本地运行时有效,但如果我从远程下载文档格式的模板,则会再次丢失图像。问题是本地计算机(/opt/profileImages文件夹)中的文档搜索图像
以下代码工作正常:
行动:
def showUserProfileImage(){
String profilePicturePath=“${grailsApplication.config.ProfilePictureDirectory路径}/${params.id}”
文件文件=新文件(profilePicturePath)
response.contentType=URLConnection.guessContentTypeFromName(file.getName())
response.outputStream