Index: lams_common/src/java/org/lamsfoundation/lams/util/UploadFileUtil.java =================================================================== diff -u -r51fb2a37254f24bb2a805d4ffd54482c779f43fa -r16db223ed22285c6c6edb6e3fa4ad7b1713cd6c1 --- lams_common/src/java/org/lamsfoundation/lams/util/UploadFileUtil.java (.../UploadFileUtil.java) (revision 51fb2a37254f24bb2a805d4ffd54482c779f43fa) +++ lams_common/src/java/org/lamsfoundation/lams/util/UploadFileUtil.java (.../UploadFileUtil.java) (revision 16db223ed22285c6c6edb6e3fa4ad7b1713cd6c1) @@ -188,7 +188,13 @@ * Returns dir where images and other resources can be uploaded. */ public static File getUploadDir(String contentFolderID, String type) { - File uploadDir = new File(UploadFileUtil.getUploadBaseDir(), contentFolderID + File.separatorChar + type); + File uploadDir = UploadFileUtil.getUploadBaseDir(); + // get content folder ID split into folders of 2 characters + String[] splitContentDir = UploadFileUtil.splitContentDir(contentFolderID); + for (int groupIndex = 0; groupIndex < splitContentDir.length; groupIndex++) { + uploadDir = new File(uploadDir, splitContentDir[groupIndex]); + } + uploadDir = new File(uploadDir, type); uploadDir.mkdirs(); return uploadDir; } @@ -214,9 +220,8 @@ */ public static String getUploadWebPath(String contentFolderID, String type) { return "/" + Configuration.get(ConfigurationKeys.SERVER_URL_CONTEXT_PATH) + "/" - + AuthoringConstants.LAMS_WWW_FOLDER + FileUtil.LAMS_WWW_SECURE_DIR - + (contentFolderID.startsWith("/") ? "" : "/") + contentFolderID - + (contentFolderID.endsWith("/") ? "" : "/") + type; + + AuthoringConstants.LAMS_WWW_FOLDER + FileUtil.LAMS_WWW_SECURE_DIR + "/" + + String.join("/", UploadFileUtil.splitContentDir(contentFolderID)) + "/" + type; } public static String getFileNameWithoutExtension(String fileName) { @@ -226,4 +231,17 @@ public static String getFileExtension(String fileName) { return fileName.substring(fileName.lastIndexOf(".") + 1); } + + /** + * Take first 12 characters of content folder ID (without "-" and "/") + * and split them in pairs of 2 + */ + private static String[] splitContentDir(String contentFolderID) { + String[] result = new String[6]; + String trimmedFolder = contentFolderID.replace("-", "").replace("/", ""); + for (int groupIndex = 0; groupIndex < 6; groupIndex++) { + result[groupIndex] = "" + trimmedFolder.charAt(groupIndex * 2) + trimmedFolder.charAt(groupIndex * 2 + 1); + } + return result; + } } \ No newline at end of file