if (UtilValidate.isNotEmpty(context.get("_uploadedFile_fileName"))) {
String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.additionalviewsize.format");
String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.server.path"), context);
String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");
FlexibleStringExpander filenameExpander = FlexibleStringExpander.getInstance(imageFilenameFormat);
String viewNumber = String.valueOf(productContentTypeId.charAt(productContentTypeId.length() - 1));
String viewType = "additional" + viewNumber;
String id = productId;
if (imageFilenameFormat.endsWith("${id}")) {
id = productId + "_View_" + viewNumber;
viewType = "additional";
}
String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "id", id, "viewtype", viewType, "sizetype", "original"));
String filePathPrefix = "";
String filenameToUse = fileLocation;
if (fileLocation.lastIndexOf("/") != -1) {
filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1);