React Native Failed Upload Image

前端 未结 1 680
眼角桃花
眼角桃花 2021-01-25 01:47

I am struggling from the past 2 days to crack the file/image upload with React Native to MongoDB. I literally read all the related forums but there is no luck. I read couple of

相关标签:
1条回答
  • 2021-01-25 02:38

    Try out the below

          let body = new FormData();
           let filename = uri.split('/').pop();
           body.append('file',  {uri:uri, name:filename, type:'image/jpg', });
           const header = {
               'Accept': 'application/json',
               'content-type': 'multipart/form-data',
             }
               fetch("http://192.168.1.5:9000/api/contrats/upload", {
                   method: 'POST',
                   headers: header,
                   body:body,
               }).then(response => response.json())
                .then(res => console.log(res))
                .catch(err => console.log("err", err)
    
    0 讨论(0)
提交回复
热议问题