繁体   English   中英

非法 base64 字符 7b

[英]Illegal base64 character 7b

我试图解码 base64 字符串以生成 excel 文件

出于上述目的,我使用 base64 解码方法

public Response addToDB(String base64){

    try{
        s=sf.openSession();
        tx=s.beginTransaction();
        /*FileInputStream file = new FileInputStream(new File("C:/Users/Ayesha.Syed/Desktop/eclipse_neon/students.xlsx")); 
        XSSFWorkbook workbook = new XSSFWorkbook(file); */
        byte[] decodedString = Base64.getDecoder().decode(base64);
        ByteArrayInputStream st = new ByteArrayInputStream(decodedString);
        XSSFWorkbook workbook = new XSSFWorkbook(st); 
        XSSFSheet sheet = workbook.getSheetAt(0);
        /*int starRow = sheet.getFirstRowNum();*/
        /*int endRow = sheet.getLastRowNum();*/

        XSSFRow row;

        for (int i = 1; i <= sheet.getLastRowNum(); i++) {

            //points to the starting of excel i.e excel first row

            Student stud=new Student();
            row = sheet.getRow(i);
            stud.setRollnumber(row.getCell(0).toString());
            System.out.println(row.getCell(0).getCellTypeEnum());

            stud.setName(row.getCell(1).toString());
            System.out.println(row.getCell(1).getCellTypeEnum());

            stud.setEnglish(row.getCell(2).toString());
            System.out.println(row.getCell(2).getCellTypeEnum());

            stud.setHindi(row.getCell(3).toString());
            System.out.println(row.getCell(3).getCellTypeEnum());

            stud.setMaths(row.getCell(4).toString());
            System.out.println(row.getCell(4).getCellTypeEnum());

            stud.setMarks(  row.getCell(5).toString());
            System.out.println(row.getCell(5).getCellTypeEnum());

            stud.setPercentage(row.getCell(6).toString());
            System.out.println(row.getCell(6).getCellTypeEnum());

            s.save(stud);
        }
        response.setStatus("200");
        response.setMessage("succesfull");
        tx.commit();
    } catch (Exception e) {
        System.err.println("Exception : " + e.getMessage());

        response.setStatus("500");
        response.setMessage("unsuccesfull");
        tx.rollback();

    } finally {
        s.close();
    }
    return response;
}

假设解码字符串并生成 excel 表以及我通过 postman 推送的数据

有同样的错误。 原来我是直接从请求参数中获取字符串,它包括整个 JSON。需要解析参数以获取实际的 base64 编码字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM