检查相似度时,报415错误

0 投票
最新提问 8月 6, 2018 用户: qiekenao (160 分)
@ResponseBody
    @RequestMapping(value = "/checkSame", method = RequestMethod.POST)
    public ApiResult checkSame(@RequestParam(value = "imageUrl", required = false) MultipartFile imageUrl) {
        ApiResult result = new ApiResult();
        try {
            SimilarResult sr = cloudUtil.similarCloud(encode(imageUrl.getBytes()));
            List<Results> list = sr.getSimilar().getResults();
            if(list.size() == 0){
                result.msg.status = 0;
                result.msg.desc = "暂无相似图片";
            }else{
                String a = sr.getSimilar().getResults().get(0).getTargetId();
                cloudUtil.getCloud(a);
                result.msg.status = 1;
                result.msg.desc = "已存在相似图片,请重新上传";
            }
        } catch (Exception e) {
            result.msg.status = 3;
            result.msg.desc = "系统问题,操作失败";
        }
        return result;
    }

    static SimilarResult sr = new SimilarResult();
    public static SimilarResult similarCloud(String file) throws Exception {
        AsyncHttpClient client = new DefaultAsyncHttpClient();
        JSONObject params = new JSONObject();
        params.put("image", file);
        Auth.signParam(params, APP_KEY, APP_SECRET);
        client.preparePost(HOST + "/similar/")
            .setBody(params.toString().getBytes())
            .execute(new AsyncCompletionHandler<Void>() {
                @Override
                public Void onCompleted(Response response) throws Exception {
                    System.out.println(response.getResponseBody());
                    Gson gson = new Gson();
                    sr = gson.fromJson(response.getResponseBody(),SimilarResult.class);
                    client.close();
                    return null;
                }
            });
        return sr;
    }

1个回答

0 投票
最新回答 8月 6, 2018 用户: albert52 (37,800 分)

上传请使用application/json

发表于 8月 6, 2018 用户: qiekenao (160 分)
有例子吗, 我没有太会用application/json
欢迎来到 EasyAR Q&A ,有什么不懂的可以尽管在这里提问,你将会收到社区其他成员的回答。
...