I am trying to send an audio file but I think I am not selecting the file correctly. I am using react-native-audio-toolkit and I was trying to use the rec object where it records, but that does not seem to work, how could I get the file to send it? code:
let rec = new Recorder("filename.mp4").record();
// Stop recording after approximately 3 seconds
setTimeout(() => {
rec.stop(err => {
// NOTE: In a real situation, handle possible errors here
let data = new FormData();
data.append("recording[path_to_recording]", rec);
data.append("recording[challenge_id]", 1);
data.append("recording[user_id]", 1);
console.log(data);
axios
.post(config.API_URL + "recordings", data, {
headers: {
Authorization: "Bearer " + this.props.auth.token
}
})
.then(res => res.data);
the log of the recording file looks like this:
Recorder {_path: "filename.mp4", _options: {…}, _recorderId: 0, _state: -2, _duration: -1, …} _duration : -1 _fsPath : "/data/user/0/com.cobrn/files/filename.mp4" _lastSync : -1 _options : autoDestroy : (...) get autoDestroy : ƒ () set autoDestroy : ƒ () proto : Object _path : "filename.mp4" _position : -1 _recorderId : 0 _state : -2 canPrepare : (...) canRecord : (...) fsPath : (...) isPrepared : (...) isRecording : (...) state : (...) proto : EventEmitter
figured it out, you need the specify the type
data.append("recording[path_to_recording]", {
uri: "file://" + rec._fsPath,
name: "filename.mp4",
type: "audio/mp4"
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.