Index: lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java,v diff -u -r1.9.4.1 -r1.9.4.2 --- lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java 29 Apr 2009 06:34:28 -0000 1.9.4.1 +++ lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java 30 Apr 2009 02:54:04 -0000 1.9.4.2 @@ -20,11 +20,10 @@ package org.lamsfoundation.lams.web; -import java.io.BufferedReader; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; import java.util.Iterator; @@ -58,6 +57,7 @@ import org.apache.commons.fileupload.DiskFileUpload; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.io.IOUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -272,8 +272,8 @@ try { if(commandStr.equals("PaintUpload")) newName = createNewPaint(validCurrentDirPath, request); - if(!commandStr.equals("FileUpload") || !isEnabled(currentFolderStr)) - throw new Exception(); + else if(!commandStr.equals("FileUpload") || !isEnabled(currentFolderStr)) + throw new Exception("Illegal command."); else newName = createNewFile(validCurrentDirPath, request); @@ -291,7 +291,10 @@ out.close(); } else { // send back URL to new Paint file - + String currentWebPath= lamsContextPath + AuthoringConstants.LAMS_WWW_FOLDER + FileUtil.LAMS_WWW_SECURE_DIR + + designFolder + typeStr +"/" + currentFolderStr; + + out.println( currentWebPath + newName); } if (debug) System.out.println("--- END DOPOST ---"); @@ -347,6 +350,7 @@ String nameWithoutExt = getUserID() + "_" + String.valueOf(new Date().getTime()); String fileName = nameWithoutExt + "." + extension; + File dir = new File(validCurrentDirPath); File pathToSave = new File(validCurrentDirPath, fileName); int counter=1; @@ -355,16 +359,19 @@ pathToSave = new File(validCurrentDirPath, fileName); counter++; } + + if(!dir.exists()) dir.mkdirs(); - if(Base64StringToImageUtil.store(validCurrentDirPath, nameWithoutExt, extension, request.getInputStream())) { - // file created - if (debug) System.out.println("--- File created: " + fileName + " ---"); - - } else { - // send error - if (debug) System.out.println("--- Error occurred writing to file: " + fileName + " ---"); - } + InputStream is = request.getInputStream(); + FileOutputStream fileos = new FileOutputStream(pathToSave); + byte[] bs = IOUtils.toByteArray(is); + + fileos.write(bs); + + fileos.flush(); + fileos.close(); + if (debug) System.out.println("--- END PAINT SAVE ---"); return fileName;