if (UtilValidate.isNotEmpty(context.get("_uploadedFile_fileName"))) {
String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.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 id = productPromoId + "_Image_" + productPromoContentTypeId.charAt(productPromoContentTypeId.length() - 1);
String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "type", "promo", "id", id));
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);