The Spring byte [] transmission

The reason things out

  For some reason, we need to transfer files between services, think only through a Byte array, or Stream passed, then set the two methods, one byte, a inpustream, the old way, upload (@RequestParam ( "id") Integer id , (@RequestParam ( "filename") String filename, (@ RequestParam ( "data") byte [] data), upload (@RequestParam ( "id") Integer id, (@RequestParam ( "filename") String filename, ( @RequestParam ( "data") InputStream data), finish up, flattered test.

Test problem

  During the test, found that the transfer spring time, can not get to the byte array is empty, no data fields. When transferring inputStream, could not get the flow, even when delivered RequestWrapper, debug body was found empty, no data. After thinking I could not find a cause of the problem.

Solution

  After many information purposes, found in the byte array transfer, may be used @RequestBody found that was able to obtain byte, flattered. The same method used when InputStream actually found not. No reason found.

Suggest

  Suggest that you transfer, you can use @RequestBody + transport bytes. If the file is too large, you can use a file server, FastDFS / FTP server can be.

 

Guess you like

Origin www.cnblogs.com/lifacheng/p/11299224.html