How to post multipart/formdata using fetch in react-native?

后端 未结 3 1548
广开言路
广开言路 2021-02-09 14:13

\"reference

i want to post Form Data like that.

what should i prepare for sending ima

3条回答
  •  我寻月下人不归
    2021-02-09 14:49

    React Native code

    fetch("url" ,{
    
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
    
        method:'POST',
    
        body: JSON.stringify(this.state.imageholder)
    
    }).catch(function(error) {
    
    console.log('There has been a problem with your fetch operation: ' + error.message);
    
    throw error;
    
    });
    

    Spring boot code

     @PostMapping(value="/",consumes = MediaType.APPLICATION_JSON_VALUE)
     public ResponseEntity saveCustomerOrder(@RequestBody String[] file) throws SerialException, SQLException {
    
        TestImg imgObj=null;
    
        for (String img : file) {
            imgObj=new TestImg();
            byte[] decodedByte = Base64.getDecoder().decode(img);
            Blob b = new SerialBlob(decodedByte);
            imgObj.setImg(b);
            testRepo.save(imgObj);
    
        }
    

提交回复
热议问题