0

I have a template that have some images one from file system and other are from project images folder.

Images in the template that are coming from the images folder of my grails application is shown perfectly in the doc file. I am using below code to render these images:

<img src="${g.resource(dir: 'images', file: 'phone-1.gif', absolute: true)}"/>

But I have an image that is coming from file system(/opt/profileImages folder). Using below code to render this image in template:

View:

<g:img uri="${g.createLink(controller: 'personalDetail', action: 'showUserProfileImage', absolute: true)}"/>

Controller:

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()
}

This is working fine, showing profile image in the browser as well as in the pdf that I downloaded using grails rendering plugin.

But problem is .doc format file. When I download the template in doc format then image is not shown.

Screenshot:

enter image description here

Can someone please tell me where I am wrong?

Or is there any other way to do this?

4

2 に答える 2

0

Kanwal Nain Singhソリューションは、サーバーがローカルで実行されている場合にのみ機能しますが、リモートから doc 形式でテンプレートをダウンロードすると、画像が失われます。問題は、ローカル マシン (/opt/profileImages フォルダー) のドキュメント検索イメージです。

次のコードは完全に機能しています。

アクション:

def showUserProfileImage() {
    String profilePicturePath = "${grailsApplication.config.profilePictureDirectoryPath}/${params.id}"
    File file = new File(profilePicturePath)
    response.contentType = URLConnection.guessContentTypeFromName(file.getName())
    response.outputStream << file.bytes
    response.outputStream.flush()
}

鬼ごっこ:

<g:img uri="${grailsApplication.config.grails.serverURL}/user/showUserProfileImage/${userImageName}"/>
于 2013-09-19T18:24:09.037 に答える