cxf +restful项目,实现一个以图片二进制流做参数的接口,接口和客户端怎么写?
以图片路径为参数的接口:
@GET
@Path("/vcardBean/{path}")
@Produces({"application/json","application/xml"})
public VCardBean getVCardBean(@PathParam("path") String path) {
    //path ="D://1.png";
     BufferedImage image = null;
        try {
            image = ImageIO.read(new File(path));
            ImageTextService imageTextService = new ImageTextService();
            String str = imageTextService.getImageText(image, "x.png", true);
            System.out.println(str);
            VCardBean vCardBean = new VCardBean();
            vCardBean.setvCardStr(str);
            vCardBean.dealVcardContent();
            return vCardBean;
        } catch (IOException e) {
            e.printStackTrace();
        }
    return null;
}
客户端代码:
private static void testGet(final String format) {

    BufferedImage image = null;
    try {
        image = ImageIO.read(new File(PATH));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "jpg", baos);
        byte[] bytes = baos.toByteArray();


        WebClient client = WebClient.create(CATEGORY_URL);
        VCardBean vCardBean = client.path("/vtwservice/vcardBean/"+PATH).accept(format).type(format).get(VCardBean.class);
        System.out.println(vCardBean.getvCardStr());
        System.out.println("链接成功!!!");

    } catch (IOException e) {
        e.printStackTrace();
    }
}

1个回答

直接传base64编码,然后再转换为stream

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐