Package net.sf.basedb.clients.web.fileupload


package net.sf.basedb.clients.web.fileupload
This package contains classes for handling file uploads from a browser using the standard described in RFC1867.

A standard design consists of three JSP pages:

  • A file selection form (index.jsp)
  • An (optional) progress page (progress.jsp)
  • An upload page (upload.jsp)
Example:
-- index.jsp
<%@ page import="net.sf.basedb.clients.web.fileupload.*" %>
<%
int progress_id = FileUpload.getNextProgressId();
%>
<html>
<head>
  <title>Upload file</title>
  <script language="JavaScript">
  function beginUpload()
  {
    window.open('progress.jsp?progress_id=<%=progress_id%>');
    document.forms['upload'].submit();
  }
  </script>
</head>
<body>
  <form action="upload.jsp?progress_id=<%=progress_id%>"
    method=post enctype="multipart/form-data" name="upload">

    Select file: <input type=file name="the_file"><br>
    Other information: <input type=text name="info" size="30">
    <p>
    <input type=button value="Upload file" onClick="beginUpload()">
  </form>
</body>
</html>

-- progress.jsp
<%@ page import="net.sf.basedb.clients.web.fileupload.*" %>
<%
int progress_id = Integer.parseInt(request.getParameter("progress_id"));
FileUploadProgress progress = FileUpload.getProgress(progress_id);
%>
<html>
<head>
  <title>Upload progress</title>
</head>
<body>
  <% if (progress == null) {%>
    Waiting for transfer...
  <%} else {%>
    Bytes transferred: <%=progress.getTransferredBytes()%><br>
    Total bytes to transfer: <%=progress.getTotalBytes()%><br>
    <% if (progress.transferIsComplete()) {%>
      Transfer completed!
    <%}%>
  <%}%>
  <%if (progress == null || !progress.transferIsComplete()) {%>
    <script language="JavaScript">
    setTimeout("location.reload()", 500);
    </script>
  <%}%>
</body>
</html>

-- upload.jsp
<%@ page import="net.sf.basedb.clients.web.fileupload.*" %>
<%
int progress_id = Integer.parseInt(request.getParameter("progress_id"));
FileUpload fu = new FileUpload(progress_id, request);
UploadedFile fuf = fu.getFile("the_file");
fuf.moveTo("/home/uploads/"+fuf.getOriginalFilename());
%>
<html>
<head>
  <title>File uploaded</title>
</head>
<body>
  Original filename: <%=fuf.getOriginalFilename()%><br>
  Mime type: <%=fuf.getMimeType()%><br>
  Size: <%=fuf.getSize()%><br>
  Other information: <%=fu.getParameter("info")%><br>
</body>
</html>
  • Class
    Description
    Objects of this class are used to handle file upload from browsers using the standard mechanism described in RFC1867.
    This class contains information extracted from the section headers for a form field or file upload field.
    This class contains information about the read status on the ServletInputStream
    Objects of this class holds information about the progress of an upload.
     
    Objects of this class can be used to get information about an uploaded file and save the file to a directory in the filesystem.