美文网首页
base64传输视频

base64传输视频

作者: KricYi | 来源:发表于2018-09-12 13:12 被阅读0次

视频前缀

data:video/mp4;base64,

图片前缀

data:image/jpeg;base64,

图片

 <img src="">

H5视频

<video controls muted webkit-playsinline="true" playsinline="true" poster="" src="">

后台

@Controller
@RequestMapping("/imgInfo")
public class ImgInfoController extends BaseController {
    @Resource
    private ImgInfoService imgInfoService;

    @RequestMapping("/add")
    public void add(@RequestParam("img") MultipartFile file, @RequestParam("id") Double id) throws IOException {
        if (id == null || file == null) {
            return;
        }
        Imginfo imginfo = new Imginfo();
        imginfo.setId(id);
        InputStream in = file.getInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buff = new byte[1024];
        int rc;
        while ((rc = in.read(buff)) != -1) {
            out.write(buff, 0, rc);
        }
        byte[] img = out.toByteArray();
        imginfo.setImg(img);

        imgInfoService.add(imginfo);
        logger.info("=====================end");
    }

    @ResponseBody
    @RequestMapping("/getById")
    public void getById(Double id) throws IOException {
        if (id == null) {
            return;
        }
        Imginfo imginfo = imgInfoService.getById(id);
        if (imginfo == null){
            return;
        }

//        DataOutputStream out =
//                new DataOutputStream(new FileOutputStream("C:\\Users\\KRIC\\Desktop\\"+id+".jpg"));
//
////得到图片二进制流,给输入流
//        InputStream is = new ByteArrayInputStream(imginfo.getImg());
//        byte[] buff = new byte[1024];
//
//        int len = 0;
//        while((len=is.read(buff))!=-1){
//            out.write(buff, 0, len);
//        }
////将流和buffer关闭
//        is.close();
//        out.flush();
//        out.close();
//        BASE64Encoder encoder = new BASE64Encoder();
//        String imgStr = encoder.encode(imginfo.getImg());
//        JSONObject json =new JSONObject();
//        String imgStr = Base64.getEncoder().encodeToString(imginfo.getImg());
//        String type = "data:image/jpeg;base64,";
//        imginfo.setBase64(type+imgStr);
//        json.put("aa",imginfo);
        String rtnStr = JSON.toJSONString(imginfo);
        toClient(rtnStr);
    }


}
public class Imginfo {
    private Double id;

    private byte[] img;


    public Double getId() {
        return id;
    }

    public void setId(Double id) {
        this.id = id;
    }

    public byte[] getImg() {
        return img;
    }

    public void setImg(byte[] img) {
        this.img = img;
    }

}

相关文章

  • base64传输视频

    视频前缀 图片前缀 图片 H5视频 后台

  • 漫画:什么是base64编码

    http传输中base64编码数据 http为文本传输协议 Base64和ASCII的区别 ASCII码的范围是0...

  • base64&标签之 小身躯大道理

    一、�浅谈base64 1.1、什么是base64? base64是网络上最常见的用于传输8B...

  • iOS中Base64编解码的使用

    为什么要进行Base64编码 Base64最早就是用于邮件传输协议中的,原因是邮件传输协议只支持ASCII字符传递...

  • base64注入

    Base64: 8bit传输URL编辑器:把标准base64的/和+变为%xx改进base64,末尾填充=,将标准...

  • base64 加密方式详解

    base64 加密方式详解 base64编码表 命名 base64是用于传输8Bit字节代码,由上图的编码表可以知...

  • Spring Security

    Basic使用Base64 加密传输密码明文传输 Digest使用MD5 加密传输避免密码明文传输 X.509 证...

  • 06 - Base64编码

    Base64编码 什么是Base64? Base64是网络上最常见的用于传输8bit字节码的编码方式之一。Base...

  • 从Base64编码的What/Why/Where讲起

    一、什么是Base64编码? Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一...

  • iOS安全之路--Base64

    一、Base64简介 Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一。Base64编码可用于在...

网友评论

      本文标题:base64传输视频

      本文链接:https://www.haomeiwen.com/subject/lmjvgftx.html