Java Groovy Grails 2019. 12. 4. 21:53
	def read_image_from_url(){ // this is for img src
		//def test_url='http://xxxx/static/distribution_2019-09-08-19-56-36.964038.png'
        URL url = new URL(params.url);

        try {
            InputStream is = url.openStream();

			render(file: is, contentType: 'image/png')
        }  catch (IOException e){

		}
	}
	def read_svg_image_from_url(){ // this is for img src
		//def test_url='http://xxxx/static/distribution_2019-09-08-19-56-36.964038.png'
        URL url = new URL(params.url);

        try {
            InputStream is = url.openStream();

			render(file: is, contentType: 'image/svg+xml')
        }  catch (IOException e){

		}
	}	
	def read_json_from_url(){
		///def JSON_URL='http://xxxx/static/cathode_2019-07-13-10-31-37.063439.json'
        URL url = new URL(params.url);
        InputStream urlStream = null;
        try {
            urlStream = url.openStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream));
            JsonSlurper jsonSlurper = new JsonSlurper();
            Object result = jsonSlurper.parse(reader);
 
            Map jsonResult = (Map) result;
			//println jsonResult

			List results = (List) jsonResult.get("Results");
            //Map user = (Map) jsonResult.get("user");
            //String name = (String) user.get("name");
            //Integer age = (Integer) user.get("age");
            //List interests = (List) user.get("interests");
			render	jsonResult as JSON
        } finally {
            if (urlStream != null) {
                urlStream.close();
            }
        }
	}

	def png_download(){ // this is for downloading image from outside url
		def imageurl = params.url
		def fnames = imageurl.split('/')
		InputStream input = new URL(imageurl).openStream();
		render file: input, contentType: 'image/png', fileName: fnames.last()
		//render 'ok'
	}

related link: http://grails.asia/grails-render-images-on-the-fly-in-gsp

 

Grails render images on the fly in GSP - Grails Cookbook

Jan 17, 2015 Snippet comments This tutorial will show how to generate PNG images on the fly and display inside a GSP. This can serve as a basis on how to create a more complex behavior. For example, creating report graphs for display in your applications.

grails.asia

https://stackoverflow.com/questions/4502278/grails-displaying-created-image-in-gsp

 

Grails: displaying created image in gsp

I'm very new to Grails so there's probably a very simple answer to this question. I'm trying to display a dynamically created image in a gsp. The image is NOT stored in a database, it's created o...

stackoverflow.com

 

posted by 사용자 kimsooil
TAG

댓글을 달아 주세요