Skip to content

How to use blueimp jQuery file upload: Empty file upload result in Struts 2, fileitems are empty

I am using Blueimp and server side is Java, Struts2. I couldn’t find examples using Java, anyway I managed to use the sample code, but I am getting "Empty file upload result" when I am trying to upload a single file also. The HTML part is the same, I am not pasting here as it may go lengthy.

The jQuery is:

$(document).ready(function () {
    'use strict';

    // Initialize the jQuery File Upload widget:

    // Enable iframe cross-domain access via redirect option:

    if (window.location.hostname === '') {
        // Demo settings:
        $('#fileupload').fileupload('option', {
            url: '//',
            maxFileSize: 5000000,
            acceptFileTypes: /(.|/)(gif|jpe?g|png)$/i,
            process: [
                    action: 'load',
                    fileTypes: /^image/(gif|jpeg|png)$/,
                    maxFileSize: 20000000 // 20MB
                    action: 'resize',
                    maxWidth: 1440,
                    maxHeight: 900
                    action: 'save'
        // Upload server status check for browsers with CORS support:
        if ($.support.cors) {
                url: '//',
                type: 'HEAD'
            }).fail(function () {
                $('<span class="alert alert-error"/>')
                    .text('Upload server currently unavailable - ' +
                            new Date())
    } else {
        // Load existing files:
        $('#fileupload').each(function () {
            var that = this;
            $.getJSON(this.action, function (result) {
                if (result && result.length) {
                    $(that).fileupload('option', 'done')
                        .call(that, null, {result: result});


The action:

public class UploadAction extends ActionSupport implements ServletRequestAware, ServletResponseAware{

    HttpServletRequest req;
    HttpServletResponse res;
  //  private File fileUploadPath=new File("c:\temp\");
    private List<File> uploads = new ArrayList<File>();
    private List<String> uploadFileNames = new ArrayList<String>();
    private List<String> uploadContentTypes = new ArrayList<String>();

    public List<File> getUploads() {
        return uploads;

    public void setUploads(List<File> uploads) {
        this.uploads = uploads;

    public List<String> getUploadFileNames() {
        return uploadFileNames;

    public void setUploadFileNames(List<String> uploadFileNames) {
        this.uploadFileNames = uploadFileNames;

    public List<String> getUploadContentTypes() {
        return uploadContentTypes;

    public void setUploadContentTypes(List<String> uploadContentTypes) {
        this.uploadContentTypes = uploadContentTypes;
    @Action(value="upload", results = { @Result(name="success", type="json")
    public String uploadFiles() throws IOException
        for (File u: uploads) {
            System.out.println("*** "+u+"t"+u.length());
        for (String n: uploadFileNames) {
            System.out.println("*** "+n);
        System.out.println("content types:");
        for (String c: uploadContentTypes) {
            System.out.println("*** "+c);
        if (!ServletFileUpload.isMultipartContent(req)) {
            throw new IllegalArgumentException("Request is not multipart, please 'multipart/form-data' enctype for your form.");
        return SUCCESS;
    public void setServletRequest(HttpServletRequest hsr) {

    public void setServletResponse(HttpServletResponse hsr) {

As I said, I have changed the action file, but I still get all empty values for files, and in the Firebug’s GET response I see "Request is not multipart, please 'multipart/form-data' enctype for your form".


You may use fileUpload interceptor to parse your "multipart/form-data" requests. It uses the same commons-fileupload implementation wrapped by the MultipartRequestWrapper in prepare operations by the Struts2 dispatcher. More about how to file upload with examples you could find here.