0

The file which i am trying to store in the back end is not a valid directory.. I think the code has a Unix directory config which i need to change to make this work in your windows. how i can identify the directory where the file is trying to be stored. i am getting the following error.

[com.keenan.oacommon.forms.services.FormServiceImpl] [checkFileDtlPathCreateIfNotExists]  - strFileMstPath is not valid
[INFO ] [java.lang.Class] [processListFiles]  - strFinalUploadPath []
[INFO ] [com.keenan.oacommon.forms.services.FormServiceImpl] [verifyFilePath]  - Validating path []
[ERROR] [com.keenan.oacommon.forms.services.FormServiceImpl] [verifyFilePath]  - strFilePath is NULL
[ERROR] [java.lang.Class] [processListFiles]  - File upload path is not valid

here is my java code..

@Override
public boolean verifyFilePath(String inFilePath) {
    boolean isFilePathValid = false;
    String strFilePath = inFilePath;

    logger.info("Validating path [" + strFilePath + "]");

    if (strFilePath == null || strFilePath.equalsIgnoreCase("")) {
        logger.error("strFilePath is NULL");
        isFilePathValid = false;
    } else {
        try {
            File fileUploadDir = new File(strFilePath);
            if (fileUploadDir.exists() && fileUploadDir.isDirectory()) {
                logger.error("File Path [" + strFilePath + "] is good");
                isFilePathValid = true;
            } else {
                logger.warn("File Path [" + strFilePath + "] is not valid");
                isFilePathValid = false;
            }
        } catch (Exception e) {
            isFilePathValid = false;
            logger.error("Exception while validating File Path [" + strFilePath + "] - " + e.getMessage(), e);
        }
    }

    return isFilePathValid;
}

@Override
public String checkFileDtlPathCreateIfNotExists(String inFilePath, String inAppSeqNo, String inUploadSeqNo) {
    boolean isFilePathValid = false;
    /* Main directory (all file uploads) */
    String strFileMstPath = null;
    File fileUploadMstDir = null;
    /* Sub directory (file uploads per application) */
    String strFileDtlAppPath = null;
    File fileUploadDtlAppDir = null;
    /* Sub-sub directory (file uploads per upload request) */
    String strFileDtlAppUploadPath = null;
    File fileUploadDtlAppUploadDir = null;

    boolean fileDirExists = false;
    String strFinalReturnPath = null;

    if (inFilePath == null || inFilePath.equalsIgnoreCase("")) {
        logger.error("inFilePath is NULL");
        isFilePathValid = false;
    } else {
        try {
            if (!inFilePath.endsWith("/"))
                strFileMstPath = inFilePath + "/";
            else
                strFileMstPath = inFilePath;

            fileUploadMstDir = new File(strFileMstPath);

            if (fileUploadMstDir.exists() && fileUploadMstDir.isDirectory()) {
                logger.error("strFileMstPath is good");

                strFileDtlAppPath = strFileMstPath + inAppSeqNo + "/";
                fileUploadDtlAppDir = new File(strFileDtlAppPath);
                if (fileUploadDtlAppDir.exists() && fileUploadDtlAppDir.isDirectory()) {
                    fileDirExists = true;
                    logger.debug("fileUploadDtlAppDir [" + fileUploadDtlAppDir.toString() + "] exists and is a dir");
                } else {
                    fileDirExists = fileUploadDtlAppDir.mkdir();
                }

                if (fileDirExists) {
                    /* Set fileDirExists to false for the next check */
                    fileDirExists = false;

                    strFileDtlAppUploadPath = strFileDtlAppPath + inUploadSeqNo + "/";
                    fileUploadDtlAppUploadDir = new File(strFileDtlAppUploadPath);

                    if (fileUploadDtlAppUploadDir.exists() && fileUploadDtlAppUploadDir.isDirectory()) {
                        fileDirExists = true;
                        logger.debug("fileUploadDtlAppUploadDir [" + fileUploadDtlAppUploadDir.toString()
                                + "] exists and is a dir");
                    } else {
                        fileDirExists = fileUploadDtlAppUploadDir.mkdir();
                    }

                    strFinalReturnPath = strFileDtlAppUploadPath;
                } else
                    logger.error("Could not create strFileDtlAppPath [" + strFileDtlAppPath
                            + "] - not attempting to create strFileDtlAppUploadPath [" + strFileDtlAppUploadPath + "]");

                if (fileDirExists)
                    isFilePathValid = true;
                else
                    isFilePathValid = false;
            } else {
                logger.info("strFileMstPath is not valid");
                isFilePathValid = false;
            }
        } catch (Exception e) {
            isFilePathValid = false;
            logger.error("Exception while validating filePath - " + e.getMessage(), e);
        }
    }

    if (isFilePathValid)
        return strFinalReturnPath;
    else
        return "";
}

@Override
@Transactional(readOnly = true)
public FileUpload getUploadedFileBySeqNo(int inFileSeqNo) {
    FileUpload fileUploadInstance = null;
    try {
        logger.debug("Fetching FileUpload for inFileUploadSeqNo [" + inFileSeqNo + "]");
        fileUploadInstance = FormsHelper.getFormDAO().getUploadedFileDetailsBySeqNo(inFileSeqNo);
        logger.debug("FileUpload for inFileUploadSeqNo[" + inFileSeqNo + "] is [" + fileUploadInstance.toString() + "]");
    } catch (Exception e) {
        logger.error("Exceoption while fetching FileUpload for inFileUploadSeqNo [" + inFileSeqNo + "] - " + e.getMessage(), e);
        fileUploadInstance = null;
    }
    return fileUploadInstance;
}

@Override
@Transactional(readOnly = true)
public FileUpload getUploadedFileByName(String inFileName, String inUploadSeqNo, String inAppSeqNo) {
    FileUpload fileUploadInstance = null;
    int uploadSeqNo = 0;
    int appSeqNo = 0;

    try {
        uploadSeqNo = Integer.parseInt(inUploadSeqNo);
        appSeqNo = Integer.parseInt(inAppSeqNo);
        logger.debug("Fetching FileUpload for inFileName [" + inFileName + "]");
        fileUploadInstance = FormsHelper.getFormDAO().getUploadedFileDetailsByName(inFileName, uploadSeqNo, appSeqNo);
        logger.debug("FileUpload for inFileName [" + inFileName + "] is [" + fileUploadInstance.toString() + "]");
    } catch (Exception e) {
        logger.error("Exception while fetching FileUpload for inFileName [" + inFileName + "] - " + e.getMessage(), e);
        fileUploadInstance = null;
    }
    return fileUploadInstance;
}

@Override
@Transactional(readOnly = false)
public boolean saveUploadedFileInfo(FileUpload inFileUpload) {
    boolean fileUploadInfoSavedSuccessfully = false;
    try {
        if (inFileUpload == null) {
            logger.error("inFileUpload is NULL / Blank");
            fileUploadInfoSavedSuccessfully = false;
        } else {
            FormsHelper.getFormDAO().saveUploadedFileInfo(inFileUpload);
            fileUploadInfoSavedSuccessfully = true;
        }
    } catch (Exception e) {
        logger.error("Exception while saving FileUpload - " + e.getMessage(), e);
        fileUploadInfoSavedSuccessfully = false;
    }

    return fileUploadInfoSavedSuccessfully;
}

@Override
@Transactional(readOnly = true)
public List<FileUpload> getUploadedFilesList(int inUploadSeqNo) {
    List<FileUpload> uploadedFilesList = null;
    try {
        logger.debug("Fetching FileUpload for inFileUploadSeqNo [" + inUploadSeqNo + "]");
        uploadedFilesList = FormsHelper.getFormDAO().getUploadedFilesList(inUploadSeqNo);
        logger.debug("FileUpload for inUploadSeqNo [" + inUploadSeqNo + "]");
    } catch (Exception e) {
        logger.error("Exceoption while fetching FileUpload for inUploadSeqNo [" + inUploadSeqNo + "] - " + e.getMessage(), e);
        uploadedFilesList = null;
    }
    return uploadedFilesList;
}

@Override
public Map<String, String> getUserNUploadDetailsForMail(int appSeqNo, String emailAddress) {
    Map<String, String> details = new HashMap<String, String>();
    try {
        logger.debug("Fetching getUserNUploadDetailsForMail appSeqNo =[" + appSeqNo + "]" + "and emailAddress = [" + emailAddress
                + "]");
        details = FormsHelper.getFormDAO().getUserNUploadDetailsForMail(appSeqNo, emailAddress);
        logger.debug("Fetched details [" + details + "]");
    } catch (Exception e) {
        logger.error("Exceoption while fetching getUserNUploadDetailsForMail " + e.getMessage(), e);
    }
    return details;
}

Thanks..

user3728616
  • 23
  • 1
  • 1
  • 3
  • You are logging that strFileMstPath is not a valid path. Why don't you log strFileMstPath to see what it looks like? – Werner Henze Sep 25 '14 at 07:22
  • I think windows dir uses the “ \ ” instead of “/ ”.here I changed in code but it give an error. I also give the direct path fileUploadMstDir = new File(“D:\n01\app\publish\onlineapps\fileuploads\CIFLF.PNG”) it also give en error. – user3728616 Sep 26 '14 at 04:34
  • As I said: log strFileMstPath! If you wonder what the output looks like, read http://stackoverflow.com/questions/1367322/what-are-all-the-escape-characters-in-java. – Werner Henze Sep 26 '14 at 07:57
  • yes! there is a table and in this table there is column in my data base. In which the path is D:/n01/app/publish/onlineapps/fileuploads for unix. I change it for windows D:\n01\app\publish\onlineapps\fileuploads.....issue resolve..... – user3728616 Sep 29 '14 at 10:40

0 Answers0