String newFileLocation = null;
filenameToUse = sizeType + filenameToUse.substring(filenameToUse.lastIndexOf("."));
if (viewType.toLowerCase().contains("main")) {
newFileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "id", id, "type", sizeType));
} else if (viewType.toLowerCase().contains("additional")) {
newFileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "id", id, "viewtype", viewType, "sizetype", sizeType));
}
String newFilePathPrefix = "";
if (newFileLocation.lastIndexOf("/") != -1) {
newFilePathPrefix = newFileLocation.substring(0, newFileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
}