'react-native audio-record send audio file
I'm trying to send react-native-audio-record to backend but I've no idea what to do next, I get the audio file but when I send it I get it's not a file here's my code
const record = async () => {
console.log("clicked")
const p = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO);
console.log(`my permission is ${p}`)
if (p !== true) {
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO)
} else {
if (!recording) {
const options = {
sampleRate: 16000,
channels: 1,
bitsPerSample: 16,
wavFile: 'test.wav'
};
AudioRecord.init(options);
setRecording(true)
AudioRecord.start()
} else {
setRecording(false)
const audioFile = await AudioRecord.stop();
const formData = new FormData();
console.log(audioFile)
formData.append('record', audioFile)
formData.append('partnerID', partnerID)
fetch('http://192.168.1.9:5000/messages/', {
method: 'POST',
body: formData,
headers: {
'Authorization': `Bearer ${JSON.parse(_access)}`,
'Content-Type': `multipart/form-data`
},
}).then((res) => {
return res.json()
}).then((data) => {
console.log(data)
})
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
