大华sdk传图片到人脸库超时

        调用企业微信api获取头像传到大华监控人脸库,大华sdk版本General_NetSDK_ChnEng_JAVA_Linux64_IS_V3.055.0000000.0.R.210602。

错误信息:

{error code: (0x80000000|2).参考  NetSDKLib.java } - {error info:网络错误,可能是因为网络超时}

//上传企业微信头像图片
         String wxtokenMsg = HttpUtils.sendGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken", "corpid=XXXX&corpsecret=XXXX");
         String accessToken= (String) JSONObject.parseObject(wxtokenMsg).get("access_token");

         String userMsg = HttpUtils.sendGet("https://qyapi.weixin.qq.com/cgi-bin/user/get", "access_token=" + accessToken + "&userid=XXXX");
         String  avatar= (String) JSONObject.parseObject(userMsg).get("thumb_avatar");//.get("avatar");

         HttpURLConnection   conn = (HttpURLConnection) new URL(avatar).openConnection();

         conn.setReadTimeout(30000);
         conn.setConnectTimeout(30000);
         // 从网络连接读取数据
         conn.setDoInput(true);
         conn.setRequestMethod("GET");
         String fileName = "";
         FileItem item = null;
         if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
             InputStream is = conn.getInputStream();
             //获取文件名称
             String newUrl = conn.getURL().getFile();
             if (newUrl != null || newUrl.length() <= 0) {
                 newUrl = java.net.URLDecoder.decode(newUrl, "UTF-8");
                 int pos = newUrl.indexOf('?');
                 if (pos > 0) {
                     newUrl = newUrl.substring(0, pos);
                 }
                 pos = newUrl.lastIndexOf('/');
                 fileName = newUrl.substring(pos + 1);
             }
           
             BufferedInputStream bis = null;
             HttpURLConnection conn1 = (HttpURLConnection) new URL(avatar).openConnection();
             bis = new BufferedInputStream(conn1.getInputStream());
             String type = HttpURLConnection.guessContentTypeFromStream(bis);
             FileItemFactory factory = new DiskFileItemFactory(16, null);
             String textFieldName = "downloadFile";  //此处任务取值
             if (!fileName.contains(".") && type != null) {
                 fileName = fileName + "." + type;//FileUtils.getFileType(type);
             }
             System.out.println("文件名为:" + fileName + "  大小" + (conn.getContentLength() / 1024) + "KB" + "   contentType=" + type);
             item = factory.createItem(textFieldName, type, false, fileName);
             OutputStream os = item.getOutputStream();
             int bytesRead;
             if(conn.getContentLength()>0) {
                 byte[] buffer = new byte[1000000];

                 while ((bytesRead = is.read(buffer, 0, buffer.length)) != -1) {
                     os.write(buffer, 0, bytesRead);
                 }
             }
             os.close();
             is.close();
         }
         if (item != null) {
             Memory memory=new Memory(1000000);

             DiskFileItem fi = (DiskFileItem)item;
             File file = fi.getStoreLocation();

             ToolKits.ReadAllFileToMemory(file.getPath(),memory);//file.getPath(),memory);


             boolean test = FaceRecognitionModule.addPerson("1", memory, "test", 1, false, "", 0, "");

         }

错误原因是:Memory memory=new Memory(1000000) 的size设置太大。

其他可能导致错误的问题:

1、设备没有网络

2、接口超时时间设置小了

3、图片太大

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值