简体   繁体   中英

Grails: How to display a decodeBase64 String to GSP Page?

The base64 String is a tiff data, I used decodeBase64() to decode it but I don't know how to display it to a GSP page.

def convertBase64ToTiff(def base64String) { 

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

def displayTiffData(def decodedData) {

}

Assuming displayTiffData is an action in a controller, you can render decoded data directly in the browser:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM