Ngfileupload upload files to the Java RESTful interface: Required ' file ' not present problem resolution

Source: Internet
Author: User

First, attach the error front error code:

	<button class= "btn btn-primary" >
        	<i class= "fa fa-upload m-r-sm" ></i> uploading file <div
        	style= " Position:absolute; top:0px; left:0px; width:150px; height:57px; Overflow:hidden; Bottom:auto; Right:auto; " >
       		   <input data-ng-disabled= "false"  class= "Form-control" type= "file" name= "file"
                	 ngf-select= " Uploadfiles ($file) "ng-model=" UploadFile "ngf-max-size=" 1.1GB "placeholder=" "style="
                 	height:47px; Position:absolute;opacity:0;cursor:pointer "required>
       		 </div>
      </button>
Back-end RESTful interface part code:

@RequestMapping (value = "/upload", method = requestmethod.post, consumes = mediatype.multipart_form_data_value)
    Public uploadsuccess Uploadexcel (@RequestParam ("file") multipartfile files) {
			.....
}
I've been tuned for half a day and always error:


Always say that the file parameter does not exist, the problem is mainly caused by the name= "file" inside the HTML code, just change it to the other value that is not called file.

The above problem is solved, but if I need to upload multiple files to Multipartfile to the array ng-fileupload upload file stream, the final solution is injected httpserveletrquest A file stream is obtained directly from this part to get the file.


    @RequestMapping (value = "/upload", method = requestmethod.post, consumes = mediatype.multipart_form_data_value)
    Public uploadsuccess Uploadexcel (HttpServletRequest request) {

        list<part> Listpart = new Arraylist<> () ;
        try {
            iterator its = request.getparts (). iterator ();
            while (Its.hasnext ()) {Part I
                = (part) its.next ();
                Listpart.add (part);
            }
            Logger.info ("File number ====>" + listpart.size ());
        } catch (IOException e) {
            e.printstacktrace ();
        } catch (Servletexception e) {
            e.printstacktrace ();
        } Return
        uploadservice.xlsxexceldeal (Listpart);
    }
Put the code, I was so resolved, I hope you can comment on the discussion, the younger brother is all ears.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.