How to send the picture under a file to the front end by streaming
This article introduces the knowledge of "how to send the pictures under a file to the front end". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
@ GetMapping ("/ getPresentImageStream")
Public void service (HttpServletResponse response, String sensorId, String presetNo, String sensorNo
String channelNo) throws ServletException, IOException {
String path = getImagePath (sensorId, presetNo, sensorNo, channelNo)
If (StringUtils.isEmpty (path)) {
Return
}
OutputStream responseStream = null
Try {
Byte [] resultBytes = FileUtils.readFileToByteArray (new File (path))
Response.setCharacterEncoding ("UTF-8")
Response.setContentType ("application/octet-stream")
ResponseStream = response.getOutputStream ()
ResponseStream.write (resultBytes, 0, resultBytes.length)
ResponseStream.flush ()
Response.flushBuffer ()
} catch (Exception e) {
If (null! = responseStream) {
Try {
ResponseStream.close ()
} catch (IOException ignored) {
}
}
}
}
This is the end of the content of "how to send the picture under a file to the front end". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!