Skip to content

A simple, cross-platform Java-based file uploader. Compatible with Java 1.4+. Plug-in your own upload logic - not limited to HTTP.

Notifications You must be signed in to change notification settings

dound/JCustomUploader

Repository files navigation

Java Custom Uploader

About: A simple, Java-based file uploader with a clean UI. It can run as an applet on your website (Java 1.4 or higher) or as part of a desktop application. This software is open-source and free to use or include in your own project.

The upload logic is pluggable, so you can use one of the included upload mechanisms (e.g., HTTP) or roll your own to upload via whatever protocol you need. The uploader automatically parallelizes uploads and provides the user with feedback on each upload's progress (including errors).

The JCustomUploader homepage has links to demos, screenshots, and more information about JCustomUploader's features. This readme is intended to help you get started with JCustomUploader.

Problem? Please report it on the JCustomUploader issues page.

Usage

First download JCustomUploader - you can either get the source code, or the latest pre-compiled jar from the downloads page. To use the uploader, you will need to instantiate an UploaderPanel. With its constructor you specify:

  • How to upload files and how many uploads to perform in parallel.
  • What kinds of files may be selected.
  • Whether to show a preview of the selected file (only for images).
  • How text in the UI refers to what you are uploading, e.g., "photo" or "item".

Using it as an Applet:

  1. In AppletDemo.java, modify the arguments to UploaderPanel() to suit your needs.
  2. Build and sign the jar (the included ant build script, build.xml, does this).
  3. Add it to your webpage just like this demo page.

Using it inside your project:

  1. Either reference the jar containing the JCustomUploader or copy the code into your source folder.
  2. Create an UploaderPanel (as above) and display it in a dialog or some other Swing container. BasicSmugMugUploader demonstrates this approach.

Example Usage

This example uploader uses 3 threads and only lets the user upload images:

// obviously you'll want to do this in a method on your applet/application

// Build the uploaders to upload to http://127.0.0.1/upload/ using HTTP POST.
final int NUM_THREADS = 3;
final UploadMechanism[] uploadMechs = new UploadMechanism[NUM_THREADS];
int maxSideLen = 1024;
for(int i=0; i<NUM_THREADS; i++) {
    uploadMechs[i] = new HTTPUploadMechanism("127.0.0.1", "/upload/");

    // override the default which just sends the file as-is
    uploadMechs[i].setUploadFileGetter(new ScaledImageGetter(maxSideLen));
}

// just use the width which the applet was given
int width = getWidth();

// what kind of things we're uploading (displayed to the user on various
// parts of the UI)
String itemType = "photo";

// only let the user select images
FileFilter filter = new ImageFileFilter();

// show a preview of files in the file chooser dialog box (only for images)
boolean showPreview = true;

// create the uploader UI (it starts the background uploader threads)
UploaderPanel newContentPane = new UploaderPanel(width, uploadMechs, itemType, filter, showPreview);

Ideas for Improvement

  • Facilitate easier internationalization.
  • Enable customization of fonts and colors via property settings. Currently these can be customized by modifying constants at the top of the relevant classes (UploaderPanel, UploadItem, and Util).
  • Add support for more programmatic interaction with the upload manager. There are some callbacks for certain events, but more hooks could be supported. It might also be helpful to expose some hooks to JavaScript code too.

Author: David Underhill
Release Date: 2010-Apr-22 (v1.01)
License: Apache License Version 2.0

About

A simple, cross-platform Java-based file uploader. Compatible with Java 1.4+. Plug-in your own upload logic - not limited to HTTP.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages