Get the App
SLTechnology News&Howtos  ›  Development  › 

How to send the picture under a file to the front end by streaming

Shulou Source: shulou.com Published: 2022-06-03 05:55:07 11月18日 Update

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!

Tags: Front-end pictures files methods content more knowledge practicality learning next dilemma reality situation articles cases editing websites industries processes high quality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology NVidia Microsoft Shulou Tech Info