uniapp微信小程序图片上传


 
 
 
 

SpringBoot后端测试代码,另外数据库中字段为Blob(MediumBlob、LongBlob)类型。

 

    //插入图片到数据库,格式为blob
    @PostMapping("/uploadImg")
    public void uploadImg(MultipartFile uploadFile, HttpServletRequest req) throws IOException, SQLException {
        Blob blob = new SerialBlob(uploadFile.getBytes());
        houseimgMapper.insertimg(blob);
    }
    
    //将数据库获取到的blob返回给前端
    /**
     * 图片路径
     */
    //注意,我的实体类定义img的类型为:  private byte[] imgurl;

    @PostMapping("/test")
    public  ResponseEntity uploadImg() throws IOException, SQLException {
        byte[] imageContent = houseimgMapper.selectById(5).getImgurl();
        return new ResponseEntity<>(imageContent, HttpStatus.OK);
    }


 

 
 

你可能感兴趣的:(微信小程序,uni-app,小程序)