E企盈小程序营销工具技术服务商 热线:4006-838-530

小程序上传图片文件,JAVA服务器接收

E企盈小程序直播系统

看过2个博主的解决方案,亲测都有效:https://blog.csdn.net/lili625/article/details/77783300假如springboot中,ListFileItem list = upload.parseRequest(request);获取长度为0请看https://blog.csdn.net/life_360/article/details/80556844我自己的后端框架springboot代码:/** * 扫图识别并记录行为结果 * @param file * @return */@RequestMapping(value = “/recognizeARCode”, method = RequestMethod.POST)public ApiResponse recognizeARCode(@RequestParam(value=”file”,required = false) MultipartFile file,   @RequestParam(value=”memberId”,required = false) String memberId,   @RequestParam(value=”memberNo”,required = false) String memberNo,   @RequestParam(value=”telNo”,required = false) String telNo,   @RequestParam(value=”openid”,required = false) String openid){String hotelGroupCode=SystemContext.getHotelGroupCode();String hotelCode=SystemContext.getHotelCode();String arCloudKey=SysOptionsCacheManager.getSysOptionsValue(hotelGroupCode,hotelCode,”ARCloudKey”);String arCloudSecret=SysOptionsCacheManager.getSysOptionsValue(hotelGroupCode,hotelCode,”ARCloudSecret”);String arCloudUrl=”http://”+SysOptionsCacheManager.getSysOptionsValue(hotelGroupCode,hotelCode,”ARCloudURL”)+”/search”;        WebAR webAR = new WebAR(arCloudKey, arCloudSecret, arCloudUrl);        String errorMsg=””;        ArLogoScanRecord arLogoScanRecord=new ArLogoScanRecord();arLogoScanRecord.setId(UUIDUtils.getUUIDNo());arLogoScanRecord.setCreateDatetime(new Date());arLogoScanRecord.setGetItemType(“p”);arLogoScanRecord.setIsHalt(“F”);arLogoScanRecord.setHotelGroupCode(hotelGroupCode);arLogoScanRecord.setHotelCode(hotelCode);if(StringUtils.isNotBlank(memberId)){arLogoScanRecord.setMemberId(memberId);}if(StringUtils.isNotBlank(memberNo)){arLogoScanRecord.setMemberNo(memberNo);}if(StringUtils.isNotBlank(telNo)){arLogoScanRecord.setTelNo(telNo);}if(StringUtils.isNotBlank(openid)){arLogoScanRecord.setOpenid(openid);}        try {            // 图片的base64数据,使用前请更换为你的图片数据String image=Base64.encode(file.getBytes());            ARResultInfo info = webAR.recognize(image);            if (info.getStatusCode() == 0) {                // statusCode为0时,识别到目标,数据在target中//记录扫图行为及结果arLogoScanRecord.setLogoId(info.getResult().getTarget().getTargetId());arLogoScanRecordService.insert(arLogoScanRecord);                return successReturn(arLogoScanRecord.getId());            } else {                // 未识别到目标               // System.out.println(info.getStatusCode());                errorMsg=”错误代码:”+info.getStatusCode()+”,”+info.getResult().getMessage();arLogoScanRecord.setErrMsg(info.getStatusCode()+”,”+info.getResult().getMessage());arLogoScanRecordService.insert(arLogoScanRecord);            }        } catch (Exception e) {            errorMsg=e.getMessage();        }       return failReturn(errorMsg);    }   wx.uploadFile({    url: ‘https://xxxxxx/upload/picture’,    filePath: filePath,//图片路径,如tempFilePaths[0]    name: ‘file’,    header : {      “Content-Type”: “multipart/form-data”    },    formData:    {      userId: 12345678 //举例说明:附加信息为用户ID    },    success: function (res) {      console.log(res);    },    fail: function (res) {      console.log(res);    },    complete: function (res) {    }  })注意:@RequestParam(value=”file”,required = false) MultipartFile file //一定要与js中name: ‘file’名称对应。js中一定要加上header

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 小程序上传图片文件,JAVA服务器接收
分享到: 更多 (0)
E企盈小程序直播营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏