cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From loop...@gmx.at
Subject Problem with Fileupload
Date Mon, 24 Apr 2006 13:42:04 GMT
Hi!

I tried the following code to upload a file, unfortunately the upload
doesn't work since the fileItems.size() == 0.
So I guess something is wrong with the HttpRequest.
I post the xsp, the HTML Form and the pattern from the sitemap.
Maybe someone has an idea what I'm doing wrong.
regards, Markus

the XSP:
<xsp:logic>
      // get the httpservletrequest from Cocoon

    HttpServletRequest objRequest =
(HttpServletRequest)objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);

      // define some constants
      long lMaxSize = 10000000;   // (10 Mb)
      int iSizeThreshold = 1024;  // bytes to hold in memory before writing
to temp location
      String strPath = "C:/tmp"; // temp location

      // create the uploader
      DiskFileUpload objFileUploads = new DiskFileUpload();

      // maximum size that will be stored in memory
      objFileUploads.setSizeThreshold(iSizeThreshold);

      // the temp location for saving data that is larger than
      //getSizeThreshold()
      objFileUploads.setRepositoryPath(strPath);

      try {
        List fileItems = objFileUploads.parseRequest(objRequest,
iSizeThreshold, lMaxSize, strPath);
        System.out.println("Number of Files : " + fileItems.size());

        Iterator it = fileItems.iterator();

        for (int i = 0; i != fileItems.size(); i++) {
          FileItem fi = (FileItem) it.next();

          // write the file to the disk
          System.out.println("File " + fi.getName() + " field " +
fi.getFieldName() + " size " + fi.getSize());
          File file = new File(strPath + "/" + i);
          file.createNewFile();
          // write the incomming file (fi) to the disk file created above
          fi.write(file);

        }
      } catch (FileUploadException fue) {
         fue.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }

  </xsp:logic>

my HTML-Form:

form action="uploadtest" method="post" enctype="multipart/form-data">
  <input type="file" name="myFile">
  <input type="submit" value="Upload">
  </form>

the entry in the sitemap:
<map:match pattern="uploadtest">
          <map:generate type="xsp" src="xsp/upload.xsp" />
          <map:serialize type="xml" />
      </map:match>

-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message