How to upload file to server using react-native

后端 未结 7 1359
渐次进展
渐次进展 2020-12-12 20:36

I am developing a app where i need to upload an image to the server. Based on the image i get a response which i need to render?.

Can you please help me how to uploa

7条回答
  •  情深已故
    2020-12-12 21:27

    My solution is using fetch API and FormData.

    Tested on Android.

    const file = {
      uri,             // e.g. 'file:///path/to/file/image123.jpg'
      name,            // e.g. 'image123.jpg',
      type             // e.g. 'image/jpg'
    }
    
    const body = new FormData()
    body.append('file', file)
    
    fetch(url, {
      method: 'POST',
      body
    })
    

提交回复
热议问题