SpringBoot将图片/文件传至前端
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot将图片/文件传至前端
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SpringBoot將圖片/文件傳至前端
- 1. 返回OutputStream
- 2. 返回base64格式
1. 返回OutputStream
@GetMapping("/download")public String download (HttpServletResponse response) {File file = new File("");byte[] bytes = new byte[1024];try (OutputStream os = response.getOutputStream();FileInputStream fis = new FileInputStream(file)){while ((fis.read(bytes)) != -1) {os.write(bytes);os.flush();}} catch (IOException e) {e.printStackTrace();}return "success";}2. 返回base64格式
@GetMapping("/base64")public String getBase64() {byte[] data = null;String dataStr = null;final Response picture = feignServer.getBase64();Response.Body body = picture.body();try (InputStream is = body.asInputStream()){data = is.readAllBytes();} catch (IOException e) {e.printStackTrace();}dataStr = Base64.encodeBase64String(data);return dataStr;}總結
以上是生活随笔為你收集整理的SpringBoot将图片/文件传至前端的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Unity3D】图片纹理压缩方式,干货
- 下一篇: 2017年html5行业报告,云适配发布