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

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

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());
    }

你可能感兴趣的:(ajax,base64)