mardi 30 octobre 2018

Commons parseRequest can not returns file

i have an multiple file input. In event onclick choose file, i created many new input, assign attribute file of newinputs equal attribute file of multiple file input at an index, but when submit, request havent file source

html code

<form action="/adv/img/upload" method="POST" enctype="multipart/form-data">
    <input type="file" name="multiplefileInput" value="" multiple="multiple" onclick="createAndAssign(this.form)">
    <button type="submit">Send</button>
    </form>

js code

for(i=0;i<fn.multiplefileInput.files[i].length;i++){
//created new inputs file
//created img view 
//created icon close image onlick close img, remove input by index
   input.file = fn.multiplefileInput.files[i];
   input.file.name = filename;
   alert(input.file.name);
}

i use alert method to check input file, it is working

java code

 try {
  // parses the request's content to extract file data
  List<FileItem> formItems = upload.parseRequest(request);
  if (formItems != null && formItems.size()>0) {
    // iterates over form's fields
    if (formItems != null && formItems.size() > 0) {
          // iterates over form's fields
          for (FileItem item : formItems) {
              // processes only fields that are not form fields
              if (!item.isFormField()) {
                  String fileName = new File(item.getName()).getName();
                  String filePath = uploadPath + File.separator + fileName;
                  File storeFile = new File(filePath);

                  System.out.println(fileName);

                  // saves the file on disk
                  item.write(storeFile);
                  request.setAttribute("message",
                      "Upload has been done successfully!");
              } else{
                String fieldValue = item.getString();
                //do somethings
              }
      }

result : null




Aucun commentaire:

Enregistrer un commentaire