Hello, I firstly made a simple program that converted images to any of the desired format by user using JAI. Then i thought of trying similar stuff on GWT. As FileOutputStream idoes not work with GWT, i first tried to make a program where user can upload an image and then download it. Now i want to kind of merge these two and i'm really very confused.
String fileName = (String)req.getParameter("fileName"); File file=new File("c:/users/rohit/desktop/"+fileName); int length=0; // Load the input image. RenderedOp src = JAI.create("fileload", file); // Encode the file as a JPEG image. OutputStream os=null; try { os =new FileOutputStream(file); } catch (FileNotFoundException e) { System.out.println("Cannot write the JPEG File"); e.printStackTrace(); } JPEGEncodeParam param = new JPEGEncodeParam(); ImageEncoder enc = ImageCodec.createImageEncoder("JPEG", os, param); try { enc.encode(src); } catch (IOException e) { System.out.println("Exception in encoding"); e.printStackTrace(); } try { os.close(); } catch (IOException e) { System.out.println("Error in closing file"); e.printStackTrace(); } ServletContext context =getServletConfig().getServletContext(); //String mimetype=context.getMimeType(fileName); String mimetype="image/jpeg"; resp.setContentType(mimetype); //resp.setContentLength((int)file.length()); resp.setHeader("Content-Disposition", "attachment; filename= \""+fileName+"\""); ServletOutputStream op = resp.getOutputStream(); byte[] buffer = new byte[4096]; DataInputStream in=new DataInputStream(new FileInputStream(file)); while ((os!=null)&&((length = os.read(buffer))!=-1)){ op.write(buffer, 0, length); } os.close(); op.flush(); op.close(); } above is the code of the server side. I store the file on hard disk after getting it uploaded from user. The above code is wrong. Basically i need an alternative to FileOutputStream. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.