source: other-projects/nz-flag-design/trunk/design-2d/image-data-to-file.jsp@ 29608

Last change on this file since 29608 was 29608, checked in by davidb, 6 years ago

Switch to using JESSIONID as part of the flagname, so everyone visiting the site gets to design their flag in private.

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1<!DOCTYPE html>
2<html>
3 <head>
4 </head>
5
6 <body>
7
8 <div style="display: none;">
9
10 <script>
11 // Set up a fallback position in case this page is accessed outside of a JSP context
12 // (i.e., the JSP blocks aren't executed)
13 var message = "Failed to execute JSP code blocks";
14 var exit_val = 404; // not currently used
15
16 </script>
17
18 <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter" %>
19
20 <%!
21
22 void writeImageDataToFile(File image_file, String image_data)
23 {
24 if (image_data == null) {
25 // Some fake data (a small arrow icon) useful for testing purposes when image_data is not supplied in the URL
26 image_data = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABL0lEQVR42q2TLW/DMBCG+1OKworCzMzMAsMCQw0zaGgaahwaXKmsoxuaVD66X3G995Jzk/Rj0rSTXsW+j8cXf+x2/22X7wu1Y0cmVlQEK8IYPsReFiOpjI7CZyFK50gDKx4DtUObQU+LXV9zcifFMHz7o5/ViZBzB0FrsvLoGeDp9HUiNUDgWwq5q98BsUo1+aERLQEK0Zhq1QWIDQNUW4BCNN7Ne7UCuHDT+DHSI3v/eZM4ADidDNjzpOxM1iMAutJ4kzztlwDQDqHM2gIw15jlbmveg1UH2BDbV3xEk5YAjNXvUiWbbbdHiSM5RDsHbQbga6IVwQ8AVkfu3a2U69tP7aEQKqPhYkM2wV9LDDkvbyPoLk3JLV8sCGP4EHtavH1MRbT5MRVz4a+P6S92BSaqyCgd7GKfAAAAAElFTkSuQmCC";
27 }
28 else {
29 // skip over 'data:image/png;base64'
30 image_data = image_data.replace("data:image/png;base64","");
31 }
32
33 byte[] image_bytes = DatatypeConverter.parseBase64Binary(image_data);
34
35 try {
36 FileOutputStream fos = new FileOutputStream(image_file);
37 fos.write(image_bytes);
38 fos.close();
39 }
40 catch (Exception e) {
41 e.printStackTrace();
42 }
43 }
44
45 %>
46
47
48 <%
49 String doc_base = getServletContext().getRealPath("/");
50 File render_dir = new File(doc_base,"render-3d");
51 File render_images_dir = new File(render_dir,"images");
52 File flag_file = new File(render_images_dir,"flag.png");
53
54 String image_data = request.getParameter("imageData");
55
56 String image_filename = request.getParameter("imageFilename");
57 if (image_filename == null) {
58 image_filename = "flag.png";
59 }
60 File full_image_file = new File(render_images_dir,image_filename);
61
62
63 writeImageDataToFile(full_image_file,image_data);
64
65 out.println("<script>");
66 out.println("message = \"Image File Saved: &lt;docBase&gt;/render-3d/images/" + image_filename + "\";");
67 out.println("</script>");
68
69 %>
70
71 </div>
72
73 <script>
74
75 document.write("<div>" + message + "</div>\n");
76
77 </script>
78
79 </body>
80
81</html>
Note: See TracBrowser for help on using the repository browser.