How to dynamically change image at URL (rename github file?)

Any luck? :slight_smile:

Sorry not yet. I started working on it and got distracted. Just making sure you are on 2.2.1 right?

I wasn’t at first, but it didn’t work after I updated either

I just tested it and it works for me. It does NOT work if it's a cloud endpoint, but does work with:

http://192.168.86.43/apps/api/2921/image?access_token=529020fb-4b3f-4d99-9353-c3881f22e2ac

mappings {
    path("/image") {
        action: [
            GET: "getImage"
        ]
    }

}

def getImage() {
	byte[] imageBytes = null
    def params = [
        uri: "https://raw.githubusercontent.com/lnjustin/wallpaper/master/cropped%20dreamstime_l_155161055.jpg",
        headers: ["Accept": "image/jpeg"]
    ]
    httpGet(params) { resp ->
        if(resp?.data != null) {
            imageBytes = new byte[resp?.data.available()]
            resp?.data.read(imageBytes)
        }
        else {
            log.error "Null Response"
        }
    }
    log.debug imageBytes.size()
    render contentType: "image/jpeg", data: imageBytes, status: 200
}

Yup, that worked! Not sure what changed since pretty sure i tried that before. Maybe I hadn't upgraded to 2.2.1 then? Doesn't matter now I suppose, because that worked. Thanks for your help on that!

1 Like