h5移动开发Ajax上传多张Base64格式图片(前端发送及后端验证)

来源:互联网 发布:韩寒 代笔 知乎 编辑:程序博客网 时间:2024/05/16 00:32

前端部分在这里(亲测可用)

http://blog.csdn.net/woyidingshijingcheng/article/details/72461349

后端代码,就base64进行解码之后,保存

    @ResponseBody    @RequestMapping(value = "/addGoodsBase64", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")    public Response addGoodsBase64(@RequestParam("base64") String[] base64) {        BASE64Decoder decoder = new BASE64Decoder();        for (String base : base64) {            try {                // Base64解码                byte[] b = decoder.decodeBuffer(base);                for (int i = 0; i < b.length; ++i) {                    if (b[i] < 0) {// 调整异常数据                        b[i] += 256;                    }                }                // 生成jpeg图片                String imgFilePath = "d://222" + UUID.randomUUID().toString() + ".png";// 新生成的图片                OutputStream out = new FileOutputStream(imgFilePath);                out.write(b);                out.flush();                out.close();            } catch (Exception e) {                e.printStackTrace();            }        }        return Response.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase());    }
原创粉丝点击