我想在节点服务器上将已上传的视频+音频blob写入磁盘。 在录制流后,RecordRTC生成了blob,我使用Angular的$ http.post将视频blob和其他一些识别数据一起发送到服务器,如下所示
// localStreamRecorder is an instance of RecordRTC
self.localStreamRecorder.getDataURL(function(dataUrl) {
var data = {
call_id: 'USR009',
media: dataUrl
};
$http.post('/api/recorded_call', data)
.then(function(res) {
console.log(res);
}, function(err) {
console.log(err);
});
});
在服务器端,我可以访问blob但是我无法使用下面的代码将blob写为有效的视频文件。
app.route('/api/recorded_call')
.post(function(req, res) {
console.log(req.body);
fs.writeFile('video-'+req.body.user_id, req.body.media,
function(err) {
if (err) {
throw err;
} else {
res.send({ 'success': true });
}
});
});
无论如何,我可以将blob(req.body的media属性)作为有效的视频文件写入磁盘,以便以后访问和查看吗?
[编辑] 我已经包含了显示以下req.body输出的日志(缩短了媒体属性)
{ call_id: '161f25090811617F62CD62',
media: 'data:audio/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQRChYECGFOAZwH/////////FUmpZpkq17GDD0JATYCGQ2hyb21lV0GGQ2hyb21lFlSua7+uvdeBAXPFh5ekuYmhmlqDgQKGhkFfT1BVU2Oik09wdXNIZWFkAQEAAIC7AAAAAADhjbWERzuAAJ+BAWJkgRAfQ7Z1Af/////////ngQCjQh+
BAACA+4PfkcoFL7c9XEormBZ3dLyTnMQQn2YnFE9bYuzBo+L0kXK1ttvkEhn2s7fbuLJzIpRZ5Z2CZM8d5HJ4MNnupGB3DeRV/S9K86keLStaGDzpe4bl9+GcEF8RiyqQbl84TE3HLCJqusEf/voXH+IZ4wm3YT1oFY8ai0PZtdnLqwzdyqUDGCVZGFMqM4swwp5765bzjWL10e7TN6UTelJ2/1VbZ1/WvUzvo1bok7S+En7XuQcBJElINlZ
Lyx4hXAnMkV+9YkDfQ0tc2hen6VJVBBPG9mQOqFkqPrB02H6u825KRpewZSwtYYe4QXxDuaniEAYAHUcB6IlTqwKFyqdj4+YUJ5ns4MuB4aPrcWMPGrt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