[opencms] Re: [opencms-dev] Out of memory error upload pdfs

Jorge Gonzalez informatico at hotelparadisepark.com
Fri Jul 1 13:33:57 CEST 2005


Is OpenCms using jakarta commons upload ?

I will paste here a piece of example code...


 The following is a brief example of typical usage in a servlet, storing the
uploaded files on disk.

    public void doPost(HttpServletRequest req, HttpServletResponse res) {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // maximum size that will be stored in memory
        factory.setSizeThreshold(4096);
        // the location for saving data that is larger than
getSizeThreshold()
        factory.setRepository(new File("/tmp"));

        ServletFileUpload upload = new ServletFileUpload(factory);
        // maximum size before a FileUploadException will be thrown
        upload.setSizeMax(1000000);

        List fileItems = upload.parseRequest(req);
        // assume we know there are two files. The first file is a small
        // text file, the second is unknown and is written to a file on
        // the server
        Iterator i = fileItems.iterator();
        String comment = ((FileItem)i.next()).getString();
        FileItem fi = (FileItem)i.next();
        // filename on the client
        String fileName = fi.getName();
        // save comment and filename to database
        ...
        // write the file
        fi.write(new File("/www/uploads/", fileName));
    }




More information about the opencms-dev mailing list