通过restTemplate向python flask api发送两张图片

2024-07-08 08:45:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我的python api有问题,它没有从我的spring boot api接收到图片

我认为问题来自我的springapi,因为当我通过邮递员将文件发送到pythonapi时,我得到了很好的答案

先谢谢你

        /** 
         * headers
         */
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        /**
         * body
         */
        MultiValueMap<String, Object> body= new LinkedMultiValueMap<>();
        body.add("photoAVerifier",new InputStreamResource(photoAVerifier.getInputStream(), photoAVerifier.getOriginalFilename()));
        body.add("photoProfil",new InputStreamResource(photoAVerifier.getInputStream(),photoAVerifier.getOriginalFilename()));
        HttpEntity<MultiValueMap<String, Object>> requestEntity
          = new HttpEntity<>(body, headers);
        /**
         * request
         */
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<ReponseApi> response = restTemplate
        .exchange(urlApiCheckPhoto,HttpMethod.POST, requestEntity, ReponseApi.class);

Tags: addapinewstringobjectbodyheadersgetinputstream

热门问题