【发布时间】:2017-02-10 18:55:09
【问题描述】:
我很难将线路连接在一起。
我正在使用videojs-record,这就是我所拥有的:
recorder.on('finishRecord', function(){
var formData = new FormData();
formData.append('file', recorder.recordedData);
$http.post('/api/submit_record', formData, { // Using Angular...
headers: {'Content-Type': 'audio/wav'}
});
});
然后在服务器端:
let bodyParser = require('body-parser');
let app = express();
app.post('/api/submit_record', bodyParser.raw({ type: 'audio/wav', limit: '1mb' }), (req, res) => {
console.log(req.body);
fs.writeFile('public/myFile.wav', req.body, function(err) {
console.log('File uploaded', fileName);
res.write('File saved');
res.end();
});
});
但我的文件最后不可读...
我知道我应该在formData 中引用file 键,但我没有找到在哪里。
阅读了很多关于此的示例,但没有人找到适合我的解决方案...
我刚刚使用来自there 的以下 curl 请求使我的后端工作:
curl -X POST --data-binary @"public/sounds/1c0334bff518849e00aadd754b1a94f0.wav" -H "Content-Type: audio/wav" http://192.168.99.100:3000/api/submit_record
我真的不介意数据是通过FormData、json 还是www-encoded 发送的,我只想这样工作。
提前致谢!
【问题讨论】:
标签: node.js audio multipartform-data