java - How to read a Multipart file as a string in Spring? -


i want post text file desktop using advanced rest client. controller:

@requestmapping(value = "/vsp/debug/compareconfig/{deviceip:.*}", method = requestmethod.post, consumes = { "multipart/form-data" }, produces = { "application/json" })  public responseentity<successresult> compareclis(httpservletrequest request, @requestparam("file") multipartfile file, @pathvariable("deviceip") string device)  { log.info(file.getoriginalfilename()); byte[] bytearr = file.getbytes(); log.info("byte length: ", bytearr.length); log.info("size : ", file.getsize());  } 

this not return value byte length or file size. want read file values stringbuffer. can provide pointers regarding this? not sure if need save file before parsing string. if how save file in workspace?

if want load content of multipart file string, easiest solution is:

string content = new string(file.getbytes()); 

or, if want specify charset:

string content = new string(file.getbytes(), "utf-8"); 

however, if file huge, solution maybe not best.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -