Project

General

Profile

Revision 4781

Added by daigle almost 12 years ago

writeTempFile was trying to write the same file as the registry. Changed to write the file to an "upload" subdirectory. Also throws IOException so errors get reported back to api.

View differences:

src/edu/ucsb/nceas/metacat/util/MetacatUtil.java
764 764
		}
765 765
	}
766 766

  
767
		/**
768
		 * Write the uploaded file to disk for temporary storage before moving
769
		 * it to its final Metacat location.
770
		 * 
771
		 * @param filePart
772
		 *            the FilePart object containing the file form element
773
		 * @param fileName
774
		 *            the name of the file to be written to disk
775
		 * @return tempFilePath a String containing location of temporary file
776
		 */
777
    public static String writeTempFile (FilePart filePart, String fileName) {
767
	/**
768
	 * Write the uploaded file to disk for temporary storage before moving it to
769
	 * its final Metacat location.
770
	 * 
771
	 * @param filePart
772
	 *            the FilePart object containing the file form element
773
	 * @param fileName
774
	 *            the name of the file to be written to disk
775
	 * @return tempFilePath a String containing location of temporary file
776
	 */
777
    public static String writeTempFile (FilePart filePart, String fileName) throws IOException {
778 778
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
779 779
        String tempFilePath = null;
780 780
        String tempDirPath = null;
781 781
        try {
782
        	tempDirPath = PropertyService.getProperty("application.tempDir");
782
        	tempDirPath = PropertyService.getProperty("application.tempDir") + FileUtil.getFS() + "uploads";
783 783
        } catch (PropertyNotFoundException pnfe) {
784 784
        	logMetacat.warn("Temp property not found.  An attempt will be made " 
785 785
        			+ "to use system temp directory: " + pnfe.getMessage());
......
805 805

  
806 806
        tempDir = new File(tempDirPath);
807 807

  
808
        // Create the temporary directory if it doesn't exist
809
        try {
810
            if (!tempDir.exists()) {
811
                tempDir.mkdirs();
812
            }
813
        } catch (SecurityException e) {
814
            logMetacat.error("Can't create directory: " + tempDir.getPath() +
815
                             ". Error: " + e.getMessage());
816
        }
817
        try {
818
            tempFile = new File(tempDirPath, fileName);
819
            fileSize = filePart.writeTo(tempFile);
820
            tempFilePath = tempDirPath + File.separator + fileName;
808
		// Create the temporary directory if it doesn't exist
809
		try {
810
			if (!tempDir.exists()) {
811
				tempDir.mkdirs();
812
			}
813
		} catch (SecurityException e) {
814
			throw new IOException("Can't create directory: " + tempDir.getPath() + ". Error: "
815
					+ e.getMessage());
816
		}
821 817

  
822
            if (fileSize == 0) {
823
                logMetacat.error("Uploaded file '" + fileName + "'is empty!");
824
            }
825
        } catch (IOException e) {
826
            logMetacat.error("MetacatUtil.writeTempFile() - IO exception when writing temporary file: " +
827
                             tempFilePath + " " + e.getMessage());
828
        }
818
		tempFile = new File(tempDirPath, fileName);
819
		fileSize = filePart.writeTo(tempFile);
820
		tempFilePath = tempDirPath + File.separator + fileName;
829 821

  
822
		if (fileSize == 0) {
823
			logMetacat.warn("Uploaded file '" + fileName + "'is empty!");
824
		}
825

  
830 826
        logMetacat.debug("Temporary file is: " + tempFilePath);
831 827

  
832 828
        return tempFilePath;

Also available in: Unified diff