阿里云OCR调用报错java.nio.file.InvalidPathException: Illegal char <:> at index 4

图片得是本地的,不能是网络上的。(百度一搜都是说什么stuct2版本什么,扯淡,都0202年了,公司都是springboot起步,真不会还有人在用struct吧???不会吧不会吧~)

解决:
修改代码方法,变成读取图片url为InputStream,赋值给request.imageURLObject

 public static Map<String, String> recognizeIdCard(String filePath, String side) {

        try {
            RecognizeIdentityCardAdvanceRequest request = new RecognizeIdentityCardAdvanceRequest();
            //读取输入流即可
            // request.imageURLObject = Files.newInputStream(Paths.get(filePath));
            InputStream inputStream= PicUtils.getInputStreamOfImageFromNetByUrl(filePath);
            request.imageURLObject = inputStream;

            request.side = side;
            RecognizeIdentityCardResponse response = ocrClient.recognizeIdentityCardAdvance(request, runtime);

            if ("face".equals(side)) {
                return JSON.parseObject(JSON.toJSONString(response.data.frontResult), new TypeReference<Map<String, String>>() {
                });
            } else {
                return JSON.parseObject(JSON.toJSONString(response.data.backResult), new TypeReference<Map<String, String>>() {
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页