Search code examples
jspopenshiftjfreechart

How can i store image in my project hosted in openshift?


i am trying to create chart and save chart in image folder. it works fine locally but when i hosted it in openshift online it doesn't work.

String root = getServletContext().getRealPath("/");
   File savedFile = new File(root+"\\images\\piechart.jpg");
   ChartUtilities.saveChartAsJPEG(savedFile, piechart, 700, 400); 

root gives null so saving is not working ... please help to store image.


Solution

  • Instead of saving the chart as an image in a local folder, you can use one of the variations of ChartUtilities.writeChartAs… to write the image to the servlet's OutputStream.

    ChartUtilities.writeChartAsJPEG(response.getOutputStream(), …);
    ChartUtilities.writeChartAsPNG(response.getOutputStream(), …);