反应原生音频发送问题



我正在尝试发送音频文件,但我认为我没有正确选择该文件。 我正在使用 react-native-audio-toolkit,我试图在它记录的地方使用 rec 对象,但这似乎不起作用,我怎样才能让文件发送它? 法典:

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);

录制文件的日志如下所示:

Recorder {_path: "filename.mp4", _options: {...}, _recorderId: 0, _state: -2, _duration: -1, ...} _期间 : -1 _fsPath : "/data/user/0/com.cobrn/files/filename.mp4" _lastSync : -1 _选项 : 自动销毁 : (...) 获取自动销毁 : ƒ (( 设置自动销毁 : ƒ ((原型: 对象 _路径 : "文件名.mp4" _位置 : -1 _recorderId : 0 _州 : -2 可以准备 : (...) 可以记录 : (...) fsPath : (...) 已准备好 : (...) 是录制 : (...) 州 : (...)原型: 事件发射器

想通了,你需要指定类型

data.append("recording[path_to_recording]", {
uri: "file://" + rec._fsPath,
name: "filename.mp4",
type: "audio/mp4"
});

最新更新