Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java操作Zimg返回json数据格式 #254

Open
leelance opened this issue Aug 13, 2019 · 0 comments
Open

Java操作Zimg返回json数据格式 #254

leelance opened this issue Aug 13, 2019 · 0 comments

Comments

@leelance
Copy link

leelance commented Aug 13, 2019

pom.xml

<dependency>
       <groupId>org.jodd</groupId>
       <artifactId>jodd-http</artifactId>
       <version>5.0.13</version>
</dependency>
@Slf4j
public class ImageUploadUtilsTests {

    @Test
    public void upload() throws IOException {
        File file = ResourceUtils.getFile("classpath:20180822153319.jpg");

        HttpRequest request = HttpRequest
                .post("http://127.0.0.1:8899/upload")
                .body(Files.toByteArray(file), suffex(file.getName()))
                ;

        HttpResponse response = request.send()
                .acceptEncoding(Charsets.UTF_8.name())
                .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        ImgResult result = JSON.parseObject(response.bodyText(), ImgResult.class);
        log.info("===>{}", result);
    }

    private static String suffex(String fileName) {
        return StringUtils.substringAfter(fileName, ".");
    }

    @Data
    static class ImgResult{
        private boolean ret;
        private ImgError error;
        private ImgInfo info;
    }

    @Data
    static class ImgError{
        private int code;
        private String message;
    }

    @Data
    static class ImgInfo{
        private String md5;
        private long size;
    }
}

返回值:

===>JSON: {"ret":true,"info":{"md5":"2a3d3a3ae4a6d8cce26f8e1b3e7a467d","size":1601925}}
===>ImgResult: ImageUploadUtils.ImgResult(ret=true, error=null, info=ImageUploadUtils.ImgInfo(md5=2a3d3a3ae4a6d8cce26f8e1b3e7a467d, size=1601925))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant