spring - MissingServletRequestParameterException -


i'm passing formdata object spring back-end:

imagebanner(banner: file, bannerpath: string, id: number, callback: (response) => void){     var formdata = new formdata();     formdata.append('name', banner.name);     console.log(formdata.get('name'));     formdata.append('file', banner);     console.log(formdata.get('file'));      this.sendpost("/upload/" + bannerpath, formdata, response => {         callback(response);     });  } 

the console log shows:

1.jpg  file {name: "1.jpg", lastmodified: 1496737372408, lastmodifieddate: tue jun 06 2017 10:22:52 gmt+0200 (w. europe daylight time), webkitrelativepath: "", size: 38983…} 

so looks formdata has values.

in back-end have this:

@requestmapping(value="/rest/upload/localeventbanner", method=requestmethod.post, headers = "content-type!=multipart/form-data")     public @responsebody string uploadfilehandler(@requestparam("name") string name, @requestparam("file") multipartfile file) {      if (!file.isempty()) {         try {             log("success");              return "you uploaded file=" + name;         } catch (exception e) {             log("fail");             return "you failed upload";         }     } else {         log("nope");         return "you failed upload " + name                 + " because file empty.";     } } 

the return i'm getting in console is:

"{"timestamp":1502745177167,"status":400,"error":"bad request","exception":"org.springframework.web.bind.missingservletrequestparameterexception","message":"required string parameter 'name' not present","path":"/beheerback/rest/upload/localeventbanner"}"

it says name isn't present when log in front-end shows name present in formdata object.

try give required = false name , file, like:

@requestparam(value = "name", required = false, defaultvalue = "defaultname") string name, @requestparam(value = "file" , required = false, defaultvalue = "defaultfile") multipartfile file 

then check values you're getting. also, check form sent using network inspector in dev mode of browser.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -