2014-03-31 34 views
0

base64 String是一個tiff數據,我使用decodeBase64()來解碼它,但我不知道如何將它顯示到GSP頁面。Grails:如何向GSP頁面顯示decodeBase64字符串?

def convertBase64ToTiff(def base64String) { 

    def decodedData = [] 
    base64String.each { 
     decodedData.add(it.decodeBase64()) 
    } 
    displayTiffData(decodedData) 
} 

def displayTiffData(def decodedData) { 

} 

回答

0

假設displayTiffData是在控制器的動作,可以在瀏覽器中直接呈現解碼的數據:

def convertBase64ToTiff(def base64String) { 

    def decodedData = [] 
    base64String.each { 
     decodedData.add(it.decodeBase64()) 
    } 
    displayTiffData(decodedData) 
} 

def displayTiffData(def decodedData) { 
    response.setHeader("Content-disposition", "inline; filename=decodedDataFilename") 
    //You can try with text/plain or render decodedData to see if the decoding function is working ok 
    response.contentType = 'image/tiff' 
    response.outputStream << decodedData 
    response.outputStream.flush() 
}