上传文件不存储

时间:2014-09-25 06:30:01

标签: java oracle

我试图存储在后端的文件不是一个有效的目录..我认为代码有一个Unix目录配置,我需要更改以使其在您的Windows中工作。 我如何识别文件试图存储的目录。 我收到以下错误。

[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

这是我的java代码..

@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;
}

谢谢..

0 个答案:

没有答案