Upload multiple files to Struts2 using Dropzone.js

I am using DropZone.js

My configuration

Dropzone.options.myAwesomeDropzone = {
                        url: 'UploadImages',
                        previewsContainer: ".dropzone-previews",
                        uploadMultiple: true,
                        parallelUploads: 5,
                        maxFiles: 20,
                        addRemoveLinks: true,
                        init: function() {
                            this.on("success", function(file, response) {
                                $('.dz-progress').hide();
                                console.log(response);
                                console.log(file);
                            });
                        }
                    }
                });

This code works fine with my localhost. I upload files to UploadImagesurl. I have entered one post in this url method which works correctly.

My problem: I do not understand what name should I use to get content on the server. Like what is the name of the imageFile variable, the imageName variable, the imageContent type, which should access my server-side implementation.

Edit: Server-side implementation of DropZone

Dropzone does not provide a server-side file processing implementation, but the file upload method is identical to the file upload forms:

<form action="" method="post" enctype="multipart/form-data">
  <input type="file" name="file" />
</form>

I turned on

<input type="file" name="file" /> 

automatically in the form so we can access it using file

<input name="file" type="file" multiple />

, file[]

  public class ImageAction extends ActionSupport {
         private List<File> file;
         private List<String> fileContentType;
         private List<String> fileFileName;

         System.out.println("Inside Image upload ");
        System.out.print("\n\n---------------------------------------\n");
        int i = 0;
        for (File f : file) {
            System.out.print("\nFile [" + i + "] ");
            System.out.print(" length: " + f.length());
            System.out.print(" name:" + getFileFileName().get(i));
            System.out.print(" contentType: " + getFileContentType().get(i));

            i++;
        }
        System.out.println("\n---------------------------------------\n");
       }
       //getter setter  
       }

.

Action.

+4
1

<input type="file" name="file" multiple /> 

name="file", :

Content-Disposition: form-data; name="file"; filename="foo.jpg"
Content-Type: image/jpeg
...........
. ...
.......
Content-Disposition: form-data; name="file"; filename="bar.jpg"
Content-Type: image/jpeg
....
.
..
.......

Struts2 FileUpload Interceptor , List<File> List<String> fileName contentType.

dropzone.js, , [] :

paramName: , . . : uploadMultiple true, Dropzone [] .

.

Content-Disposition: form-data; name="file[0]"; filename="foo.jpg"
Content-Type: image/jpeg
...........
. ...
.......
Content-Disposition: form-data; name="file[1]"; filename="bar.jpg"
Content-Type: image/jpeg
....
.
..
.......

Struts2 .

, , dropzone.js, Struts2:

  • dropzone.js dropzone-struts2.js;
  • "[" + n + "]" ( 866 )
  • return "" + this.options.paramName + (this.options.uploadMultiple ? "[" + n + "]" : "");
    

    return "" + this.options.paramName; //+ (this.options.uploadMultiple ? "[" + n + "]" : "");
    

Struts2 .

+1

All Articles