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:

MetacatHandler.java
2651 2651
        Logger logMetacat = Logger.getLogger(MetacatHandler.class);
2652 2652
        PrintWriter out = null;
2653 2653
        String action = null;
2654
        File tempFile = null;
2654 2655
        
2655 2656
        // Parse the multipart form, and save the parameters in a Hashtable and
2656 2657
        // save the FileParts in a hashtable
......
2692 2693
                    // it's a file part
2693 2694
                    FilePart filePart = (FilePart) part;
2694 2695
                    String fileName = filePart.getFileName();
2695
                    String fileTempLocation;
2696 2696
                    
2697 2697
                    // the filePart will be clobbered on the next loop, save to disk
2698
                    fileTempLocation = MetacatUtil.writeTempUploadFile(filePart, fileName);
2699
                    fileList.put(name, fileTempLocation);
2698
                    tempFile = MetacatUtil.writeTempUploadFile(filePart, fileName);
2699
                    fileList.put(name, tempFile.getAbsolutePath());
2700 2700
                    fileList.put("filename", fileName);
2701
                    fileList.put("name", fileTempLocation);
2701
                    fileList.put("name", tempFile.getAbsolutePath());
2702 2702
                } else {
2703 2703
                    logMetacat.info("MetacatHandler.handleMultipartForm - " +
2704 2704
                    		        "Upload name '" + name + "' was empty.");
......
2787 2787
            out.println("Error: action not registered.  Please report this error.");
2788 2788
            out.println("</error>");
2789 2789
        }
2790
        
2791
        // clean up the temp file
2792
        if (tempFile != null && tempFile.exists()) {
2793
        	tempFile.delete();
2794
        }
2790 2795
        out.close();
2791 2796
    }
2792 2797
    

Also available in: Unified diff