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.