Project

General

Profile

« Previous | Next » 

Revision 7823

use standard File.createTempFile() method for uploaded data files and delete them when we are done with them. https://projects.ecoinformatics.org/ecoinfo/issues/6008

View differences:

MetacatUtil.java
400 400
	 *            the name of the file to be written to disk
401 401
	 * @return tempFilePath a String containing location of temporary file
402 402
	 */
403
    public static String writeTempUploadFile (FilePart filePart, String fileName) throws IOException {
404
        String tempFilePath = null;
403
    public static File writeTempUploadFile (FilePart filePart, String fileName) throws IOException {
404
        File tempFile = null;
405 405
        String tempDirPath = null;
406 406
        try {
407 407
        	tempDirPath = PropertyService.getProperty("application.tempDir") + FileUtil.getFS() + "uploads";
......
410 410
        			+ "to use system temp directory: " + pnfe.getMessage());
411 411
        }
412 412
        long fileSize;
413
        File tempFile;
414 413
        File tempDir;
415 414

  
416 415
        if ((fileName == null) || fileName.equals("")) {
417
            return tempFilePath;
416
            return tempFile;
418 417
        }
419 418
				
420 419
        // the tempfilepath token isn't set, use Java default
......
440 439
					+ e.getMessage());
441 440
		}
442 441

  
443
		tempFile = new File(tempDirPath, fileName);
442
		//tempFile = new File(tempDirPath, fileName);
443
		tempFile = File.createTempFile("upload", ".tmp", tempDir);
444 444
		fileSize = filePart.writeTo(tempFile);
445
		tempFilePath = tempDirPath + File.separator + fileName;
446 445

  
447 446
		if (fileSize == 0) {
448 447
			logMetacat.warn("Uploaded file '" + fileName + "'is empty!");
449 448
		}
450 449

  
451
        logMetacat.debug("Temporary file is: " + tempFilePath);
450
        logMetacat.debug("Temporary file is: " + tempFile.getAbsolutePath());
452 451

  
453
        return tempFilePath;
452
        return tempFile;
454 453
    }
455 454

  
456 455
    /**

Also available in: Unified diff