Skip navigation links
3.6.0: 2015-10-08

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

This package contains classes for handling file uploads from a browser using the standard described in RFC1867.

See: Description

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

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:

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>
Skip navigation links
3.6.0: 2015-10-08