React Native: Use fetch with FormData to upload file



  • const formData = new FormData()
    formData.append('file', {
      uri: path,
      name: 'audio.aac',
      type: 'audio/aac',
    })
    
    try {
      const res = await fetch(API_UPLOAD_AUDIO_FILE, {
        method: 'POST',
        headers: {
          'Content-Type': 'multipart/form-data',
        },
        body: formData,
      })
      const json = await res.json()
    } catch (err) {
      alert(`uploadAudio error is ${err}`)
    }