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

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

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

javascript - Restarting Supervisor and effect on FlaskSocketIO -